Книга: C# 2008 Programmer

Skipping an Iteration

Skipping an Iteration

To skip to the next iteration in the loop, you can use the continue keyword. Consider the following block of code:

for (int i = 0; i < 9; i++) {
 if (i % 2 == 0) {
  //---print i if it is even---
  Console.WriteLine(i);
  continue;
 }
 //---print this when i is odd---
 Console.WriteLine("******");
}

When i is an even number, this code block prints out the number and skips to the next number. Here's the result:

0
******
2
******
4
******
6
******
8

Оглавление книги


Генерация: 0.058. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз