KwickAcademy Java · 5 min · free
Jump Statements and Loop Variations: break, continue and Labels
break and continue traced step by step, labelled break and continue for nested loops, infinite and empty loops, and exam loop variations.
Follows the syllabus of: ICSE Class 9 Computer Applications, ISC Class 11 Computer Science (868)
On screen in this lesson
Jump statements
| break: leave the loop now |
| continue: skip the rest of this iteration |
| Both are usually placed inside an if |
break vs continue
| Point | break | continue |
|---|---|---|
| Loop after it | ends | goes on |
| Jumps to | line after loop | next iteration |
| Ends a switch | yes | no |
Infinite loops
| Loop | Why endless | Use |
|---|---|---|
| for (;;) | no condition | menus, servers |
| while (true) | always true | with a break |
| while (i <= 5) | i never updated | a bug |
Loop variations in exams
| Variation | Example | Runs |
|---|---|---|
| Counting down | i = 5; i >= 1; i-- | 5 times |
| Step of 2 | i=1; i<=9; i+=2 | 5 times |
| Two variables | i = 1, j = 9; i < j | while i < j |
| Parts left out | for (; i <= 5;) | like while |
Recap
| break ends the loop; continue skips one iteration |
| A label lets break or continue act on the outer loop |
| for (;;) and while (true) are infinite loops |
| A loop ending in ; has an empty body |
| Trace variations by writing each value of i |
Quick answers
How do you leave two nested loops at once?
Label the outer loop and write break outer;
What does continue do in a for loop?
It jumps to the update, so the loop carries on with the next iteration.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
What does break print here?41 sec
How do you exit two loops at once?42 sec
Why is for(;;) infinite?44 sec
How many times does for (i=1; i<=9; i+=2) run?44 secThe full lesson, in text
Hello students, welcome to Kwickprep. A break inside two loops leaves only the inner one. So how do you jump out of both at once? Today we trace break and continue step by step, and learn labels for nested loops. We will also meet infinite loops, empty loops, and the loop variations that board papers love.
A jump statement moves control to another place, instead of the next line. Break stops the loop completely, and control goes to the line after the loop. Continue skips only the rest of the current iteration, and the loop carries on with the next one. We usually put them inside an if, so they act only in a special case.
Let us trace it. When i is one, i equals three is false, so it prints one. When i is two, it prints two. When i is three, the condition is true, and break ends the loop at once. Four and five never run, and control goes to the line after the loop, which prints Done.
Now the same loop with continue. When i is one and two, they print as before. When i is three, continue skips the print, but the loop does not end. In a for loop, continue jumps to the update, so i becomes four. Four and five print, and then Done.
Here is the difference in one table. After break, the loop ends, but after continue, the loop goes on. Break jumps to the line after the loop, while continue jumps to the next iteration. Break is also used to end a switch, and continue only ever affects a loop.
A label is a name followed by a colon, written just before a loop. Here the outer loop is labelled outer. A plain break would leave only the inner loop. But break outer leaves both loops at once. So only one, one prints, and the program ends.
Pause and predict. This time it says continue outer. When j reaches two, Java skips the rest of the inner loop, and starts the next iteration of the outer loop. So for each i, only j equals one prints. The output is one one, two one, and three one.
An infinite loop is a loop whose condition never becomes false, so it never stops by itself. For with two semicolons and nothing else has no condition, so Java treats it as always true. While true is also always true, and we stop it from inside with a break. But a while loop that forgets to update i is a bug, and the program hangs.
An empty loop has no body, only a semicolon. Older textbooks call it a time delay loop, because it only counts. Here i is declared outside, so we can print it later. The loop runs while i is five or less, and stops when i becomes six. So it prints six, just once.
Board papers often change the normal loop, so learn these variations. A loop can count down, using i minus minus. It can move in steps, like i plus equals two, which gives one, three, five, seven and nine. It can use two variables, separated by a comma. And any of the three parts can be left out, which makes a for loop behave like a while loop.
Here is a typical board question. How many times does the loop run, and what prints? Trace it. First i is one and j is ten. Then i is three and j is eight, then i is five and j is six. Next i is seven and j is four, so i less than j is false. The loop ran three times, and it prints seven four.
Let us recap. Break ends the loop, while continue skips only the current iteration. A label lets break or continue act on an outer loop. For with two semicolons and while true are infinite loops. A loop that ends in a semicolon has an empty body. And to answer variation questions, write down every value of the variables, step by step.
Courses that teach this
| Course | Unit |
|---|---|
| ICSE Class 9 Computer Applications | Conditional Constructs in Java |
| ISC Class 11 Computer Science (868) | Statements, Control Flow and Functions |
| Programming All levels Java | Control Flow and Iteration |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

