Continue statements

Feeling what the operator is doing continuein the loop do...while(false), I mocked a simple test case (pseudocode):

count = 0;
do {
    output(count);
    count++;
    if (count < 10)
        continue;
}while (false);

output('out of loop');

The solution was, to my surprise:

0
out of loop

A little confused, I changed the loop from do...whileto for:

for (count = 0; count == 0; count++) {
    output(count);
    if (count < 10)
        continue;
}
output('out of loop');

Although functionally not the same, the goal is almost the same: to make the condition only complete the first iteration, and in the following continue (until a certain value is reached, purely to stop possible infinite loops). They may not run the same number of times, but the functionality here is not an important bit.

The output was the same as before:

0
out of loop

Now insert a simple loop while:

count = 0;
while (count == 0) {
    output(count);
    count++;
    if (count < 10)
        continue;
}
output('out of loop');

Once again, the same conclusion.

, continue " ". , : continue ? ?

(( , JavaScript, , -... js ))

+5
4

for continue for ( ), (2- ), , . .

( do-while) , , . .

+5

continue " " . , .

, , false, count ==0. false .

, continue . .

+1

continue . haelp:

#include <iostream>
using namespace std;

int main() {

    int n = 0;

    do {
        cout << n << endl;
        n += 1;
        if ( n == 3 ) {
            continue;
        }
        cout << "n was not 3" << endl;
    } while( n != 3 );

}

:

0
n was not 3
1
n was not 3
2

, continue while() . for() while().

+1

continueproceeds to the next iteration when it is used in a loop. breakexits the current block. Typically, an interrupt is used to exit a loop, but it can be used to exit any block.

for (int i = 0; i < 1000; i++) {
  if (some_condition) {
    continue; // would skip to the next iteration
  }

  if (some_other_condition) {
    break; // Exits the loop (block)
  }

  // other work
}
0
source

All Articles