- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to control for loop using break and continue statements in C#?
Break statement terminates the loop. To use it in a for loop, you can get input from user everytime and display the output when user enters a negative number. The output gets displayed then and exited using the break statement −
for(i=1; i <= 10; ++i) { myVal = Console.Read(); val = Convert.ToInt32(myVal); // loop terminates if the number is negative if(val < 0) { break; } sum += val; }
In the same way, continue statement in a for loop works, but it will not display the negative numbers. The continue statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating −
for(i=1; i <= 10; ++i) { myVal = Console.Read(); val = Convert.ToInt32(myVal); // loop terminates if the number is negative and goes to next iteration if(val < 0) { continue; } sum += val; }
- Related Articles
- Loops and Control Statements (continue, break and pass) in Python
- How to use break and continue statements in Java?
- break, continue and label in Java loop
- Describe JavaScript Break, Continue and Label Statements
- Difference between continue and break statements in Java
- What is the difference between break and continue statements in C#?
- Finding how many time a specific letter is appearing in the sentence using for loop, break, and continue - JavaScript
- What is the difference between break and continue statements in JavaScript?
- Loop Control Statements in Perl
- Loop Control Statements in Python
- How to break a for loop in Python?
- Difference Between break and continue
- How to use continue statement in Python loop?
- What are the loop control statements in C language? Explain with flow chart and program
- Nested for loop and other related statements in C language

Advertisements