continue
break leaves the loop. Its partner continue only skips the rest of this round: the loop goes straight back to its start and carries on. It's handy for skipping input that shouldn't be handled:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
int number = Integer.valueOf(scanner.nextLine());
if (number == 0) {
break;
}
if (number % 2 != 0) {
System.out.println(number + " is odd, skipped");
continue;
}
System.out.println("Half of " + number + " is " + number / 2);
}
}
}
8
5
12
0Half of 8 is 4
5 is odd, skipped
Half of 12 is 6For 5 the continue runs, so the "Half of" line is skipped for that round only. The loop then reads 12 as usual.
A loop often starts with its checks, each ending in break or continue, and then does the real work for the input that got through them.