Continue Statement – It is used for returning control to loop for next increment
package practice;
public class ContinueStatment {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
if (i == 3) {
continue;
}
System.out.println(i);
}
}
}
Explanation – once i become 3 the loop will not print 3 , instead it will increment i and print 4.
The loop runs from
i = 0
toi < 5
(i.e. 0 to 4).Inside the loop:
If
i == 3
, thecontinue
statement is executed.continue
skips the rest of the loop body for that iteration and jumps to the next iteration.
So, when
i == 3
,System.out.println(i)
is skipped.
Output-
0
1
2
4