Saturday, June 12, 2021 19:46

Table of contents >> Introduction > Continue operator

Continue operator

In the last article, we spoke about the Break operator being used to immediately stop a loop and continue the execution with the statements that follow after the loop. The Continue operator works somehow in the same way, with the only difference that it will only make the execution skip the current iteration of the loop. In other words, it skips the current cycle, without terminating the loop.

For instance, lets take the following code:

In the above code, we declared an integer, then a While loop that will run until our integer is less than 10. Inside our loop, we increment our integer, then we are doing an If-Else check: if the reminder of our integer being divided by 2 is not 0 (meaning the number is odd), we simply skip the current loop cycle; if it is 0 (the number is even), then we display the number on the console output.

The result follows:

continue operator

The concepts explained in this lesson are also shown visually as part of the following video:

Tags: , ,

Leave a Reply



Follow the white rabbit