You have already seen the break statement used in an earlier chapter of this tutorial. It was used to "jump out" of a switch statement.The break statement can also be used to jump out of a loop.This example jump
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...
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
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: ...
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 »...