However, when the continue statement is executed, it behaves differently for different types of loops: In awhileloop, the condition is tested, and if it is true, the loop is executed again In afor loop, the increment expression (e.g. i++) is first evaluated, and then the condition is...
You have already seen thebreakstatement used in an earlier chapter of this tutorial. It was used to "jump out" of aswitchstatement. Thebreakstatement can also be used to jump out of aloop. This example stops the loop when i is equal to 4: ...
Thebreakstatement can also be used to jump out of a loop: Example for(leti =0; i <10; i++) { if(i ===3) {break; } text +="The number is "+ i +""; } Try it Yourself » In the example above, thebreakstatement ends the loop ("breaks" the loop) when the loop counter...
if(i ==4) { i++; continue; } cout << i <<"\n"; i++; } Try it Yourself » Exercise? What does thebreakstatement do in a loop? Exits the loop immediately Skips the current iteration Repeats the current iteration Submit Answer »...