The correct answer is: B. terminate loops or to exit from a switch.
The continue
statement is used to terminate the current iteration of a loop and continue with the next iteration. It can be used in any type of loop, including for loops, while loops, and do-while loops.
The continue
statement is not used to permit two different expressions to appear in situations where only one expression would ordinarily be used. This is the job of the if
statement.
The continue
statement is not used to alter the normal sequence of program execution by transferring control to some other part of the program. This is the job of the goto
statement.
The continue
statement is not used to terminate a switch statement. The break
statement is used to terminate a switch statement.
Here is an example of how the continue
statement can be used in a for loop:
for (int i = 0; i < 10; i++) {
if (i == 5) {
continue;
}
System.out.println(i);
}
In this example, the continue
statement will cause the loop to skip the iteration where i
is equal to 5. The output of this code will be:
0
1
2
3
4
6
7
8
9