It was a rainy Tuesday morning where I introduced the Loop control in C. The kind where the ceiling fans spin with no real purpose and the whiteboard markers begin to dry mid sentence. We had just begun our session on loops when a boy from the back row cheeky and always curious raised his hand with a puzzled frown. “Sir, can I just jump out of the loop? Like just escape it?” The class chuckled. I smiled, because I knew what he was really asking: “Can I break the rules… in code?” That day, I introduced them to three deceptively simple weapons in C for loop control: break, continue, and the always controversial goto. And what followed was one of the most interesting class sessions of the semester.
Loop Control Chapter 1: Breaking Free
Let’s start with break because that’s where most students find both clarity and confusion.

“Imagine you’re in a boring family dinner,” I told them, “and halfway through, you realize you forgot to submit your assignment. What do you do?”
“You leave!” one of them laughed.
“Exactly. That’s break.”
A simple example:
int n;
while (1) {
printf(“Enter a number (0 or negative to quit): “);
scanf(“%d”, &n);
if (n <= 0) {
break; // Exit the loop immediately
}
printf(“You entered: %d\n”, n);
}
It’s clean. It’s intuitive. You give the user the wheel, and the moment they want to stop break lets them.
But oh, the mistakes I’ve seen.
One student once wrote this:
for (int i = 0; i < 10; i++) {
if (i == 3)
break;
printf(“%d\n”, i);
}
He was confused why only 0, 1, 2 printed.
“I thought it would print all numbers except 3,” he mumbled.
I walked to the board, drew a ladder with ten steps, and said, “Imagine climbing this. When you hit step 3, you jump off the ladder. You don’t skip that step you exit the climb.”
That’s break.
It’s not skip; it’s exit. Game over.
Loop Control Chapter 2: Continue Walking, Just Skip the Puddle
The next day, I had a different class. A girl in the front row, always precise, asked:
“Sir, I want to skip only some values in a loop not exit. Is that possible?”
That’s when I brought in continue.
I pulled out an old analogy I love:
“Imagine walking on a footpath filled with puddles. You don’t want to go home you just don’t want to step in the puddles.”
That’s continue.
You stay in the loop, but you skip the dirty part.
Example:
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) continue;
printf(“%d “, i);
}
It prints: 1 3 5 7 9
We skipped the even numbers.
But the loop kept going. That’s the beauty of continue.
One mistake I remember clearly:
A student used it like this:
for (int i = 1; i <= 10; i++) {
if (i == 5) continue;
printf(“%d “, i);
i++; // Oops!
}
Result? A total mess.
It printed: 1 3 5 7 9
Wait, wasn’t 5 supposed to be skipped? Yes, but…
I explained: “When you use continue, it jumps to the loop increment part, not the next line. So adding i++ manually causes chaos.”
She sighed. “So… it’s like jumping too far ahead?”
“Exactly. One jump is enough. Don’t leap twice.”
Loop Control Chapter 3: The Forbidden Teleport: goto
Ah, goto.
I remember the first time I used it. I felt powerful.
int i = 0;
start:
if (i < 5) {
printf(“%d “, i);
i++;
goto start;
}
Worked like magic. But then I added nested loops, some conditions, a few more gotos… and by the time I was done, I didn’t know where I was going.
I call it code teleportation.
It looks cool. But too much teleporting and you’ll end up in a wormhole.
I shared a real story with my class:
I once mentored a student’s college project bank management system in C. His code had six goto labels. SIX.
Every time something failed login, withdrawal, balance check he’d teleport the program to another label.
I told him, “You’re not writing a program. You’re designing a haunted house with trapdoors.”
He cleaned it up later using proper loops and conditionals. But the fear stayed with me.
Even today, when I see goto, I flinch a little.
Practical Uses: When Are These Okay?
I always emphasize that these are tools, not sins. Used wisely, they shine.
When break makes sense:
- Exiting a loop when a condition is met early.
- Searching an array for an element no need to loop till the end.
int arr[] = {2, 4, 6, 8, 10};
int key = 6;
int found = 0;
for (int i = 0; i < 5; i++) {
if (arr[i] == key) {
found = 1;
break;
}
}
When continue is perfect:
- Skipping over invalid input.
- Skipping a calculation when data is missing.
for (int i = 1; i <= 10; i++) {
if (i % 3 == 0) continue;
printf(“%d “, i);
}
When goto is sometimes acceptable:
- Exiting deeply nested loops.
- Error handling in large C programs, especially in legacy or system level code.
But for beginners?
I say, learn to live without it. Build logic with loops and conditions first.
A Real Class Project: Number Guessing Game
To tie it all together, I once gave my students a mini project.
“Build a number guessing game. You get 5 tries. Exit early if guessed correctly. Skip any invalid attempts.”
A student came back with this:
#include <stdio.h>
int main() {
int secret = 7;
int guess;
for (int i = 1; i <= 5; i++) {
printf(“Attempt %d Enter guess: “, i);
scanf(“%d”, &guess);
if (guess < 0) {
printf(“Invalid guess. Try again.\n”);
continue;
}
if (guess == secret) {
printf(“Correct! You win.\n”);
break;
}
printf(“Wrong guess.\n”);
}
return 0;
}
He used break and continue exactly how they should be. No goto, no mess.
Just clean, readable logic.
That’s the kind of code that makes you proud as a teacher.
Common Mistakes and How I Explain Them
- Using break inside a loop and expecting the loop to pause, not end.
- I say: “Break is not a pause. It’s a mic drop. You walk out.”
- Using continue and forgetting loop logic after it.
- I say: “It skips the rest so anything after that line is ignored. Always plan the order.”
- Goto misuse.
- I say: “Every time you use goto, ask yourself can I solve this with loops or conditions?”
- Using break outside of loops.
- Compiler errors are kind here. But the intent matters. Teach proper scope.
How I Wrap Up This Topic
By the end of the session, I usually ask them one thing:
“Would you rather be in control or teleport blindly?”
That hits home. They start appreciating the clarity that comes from structured logic.
Break and continue offer precision.
Goto offers chaos, and a rare escape like smashing a glass in case of fire.
We don’t ban tools.
We learn when to use them and more importantly, when not to.
Can break be used in if else directly?
Only if it’s inside a loop or switch case. Using it outside will cause a compile error.
What happens if we use continue in a while loop?
It skips to the condition check and goes to the next iteration.
Is goto ever mandatory?
Rarely. In C system programming (kernel code, device drivers), goto is used for error handling. But in most cases, it can be avoided.
Can break and continue be nested inside multiple loops?
Yes, but they affect only the nearest loop they’re inside.