Continue Statement

Sir/Maam,
Does the continue statement take us to the nearest loop or the one farthest?

hello @diganta_7777

continue will skip all instructions of loop that are written after it(continue) and loop start performing next iteration .

for example->
int main() {

// loop from 1 to 10

for ( int i = 1; i <= 10; i++) {

// If i is equals to 6,

// continue to next iteration

// without printing

if (i == 6)

continue ;

else

// otherwise print the value of i

printf ( "%d " , i);

}

return 0;

}

Output:

1 2 3 4 5 7 8 9 10 (note 6 is not printed becuase we skip the execution for i=6

Suppose there is a nested loop ex:

for(){ for() {…if()continue}}…in this case which loop does it move to?

it will skip instructions of only inner loop becuase u have used continue statement inside inner loop.

And then go back to inner loop, right?

yeah right, it(inner loop) will start doing next iteration when it will encounter continue .

Understood! Thanks !