Break And Continue

Break

break is used to forcefully stop loop even if it's condition is met.

Output:

line 6 ends the loop though it's condition is fulfilled.

Value of sum is formed by adding i to it (1 + 2 + 3 + 4 + 5 + 6 = 21).

Continue

Continue skips the current iteration of the loop.

Output:

line 4stops the current iteration thus 4 isn't printed.

Unlike breakit doesn't skip the entire loop.