loop and do...while loop ) and switch statements.
continue statement is used to skips the execution of the program to the next iteration.
Let's see the flow diagram of both
Break statement flow diagram
continue statement flow diagram
In the above images you can see comparison between
continue statements are used inside conditional statements, so when certain condition statisfy you can choose to
break the loop or choose to
continue to next iteration.
break statement helps use to exit out of the loop when certain condition satisfies.
For example: we want to exit a loop when our initialize or some variable achieve a value, then we can check
for that condition and if condition statisfies then use
break statement to exit out of the loop.
We have already seen the
break statement when we were learning switch statement. The
break statement was used there to jump out of
Here is an example of a
break statement which jumps out of loop when count (some variable)
becomes equal to 4.
continue statement is used to jump one iteration of the loop, means you can skip one time
execution of the loop using it. For example: while executing a loop if you want not to work on a variable for
some value 4, then you can simply skip it by using
In the example below continue statement executes when count is equal to 4, and skip the code below it without executing.
continue statements can't be used in forEach, map,
reduce, etc because these are functions and break and continue can only be used in loops.
label_name: // Single or Multiple Code // Statements
label name can be used to
continue the block of code.
break label_name; continue label_name;