
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use Continue Statement in While Loop in C#
The continue statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
The continue statement in C# works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between.
For the while loop, continue statement causes the program control passes to the conditional tests.
The following is the complete code to use continue statement in a while loop.
Example
using System; namespace Demo { class Program { static void Main(string[] args) { /* local variable definition */ int a = 10; /* loop execution */ while (a < 20) { if (a == 15) { /* skip the iteration */ a = a + 1; continue; } Console.WriteLine("value of a: {0}", a); a++; } Console.ReadLine(); } } }
Output
value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19
Advertisements