In which statements, does a ‘continue’ statements cause the control to go directly to the test condition and then continue the looping process? A. ‘for’ and ‘while’ B. ‘while’ and ‘if-else’ C. ‘do-while’ and ‘if-else’ D. ‘while’ and ‘do-while’ E. None of the above

[amp_mcq option1=”‘for’ and ‘while'” option2=”‘while’ and ‘if-else'” option3=”‘do-while’ and ‘if-else'” option4=”‘while’ and ‘do-while’ E. None of the above” correct=”option4″]

The correct answer is D. ‘while’ and ‘do-while’.

A continue statement causes the control to go directly to the test condition and then continue the looping process. This means that the current iteration of the loop will be skipped, but the next iteration will be executed.

The continue statement can be used in both while and do-while loops. In a while loop, the continue statement is executed after the condition has been evaluated. In a do-while loop, the continue statement is executed after the body of the loop has been executed.

Here is an example of a while loop that uses a continue statement:

int i = 0;
while (i < 10) {
if (i == 5) {
continue;
}
System.out.println(i);
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

Here is an example of a do-while loop that uses a continue statement:

int i = 0;
do {
if (i == 5) {
continue;
}
System.out.println(i);
i++;
} while (i < 10);

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

The continue statement can be a useful tool for controlling the flow of a program. It can be used to skip over unwanted iterations of a loop, or to prevent a loop from executing altogether.

Exit mobile version