Quiz-Break and Continue Interview Questions for Embedded C: Quiz and Code Challenges-Free Embedded C Tutorial

Need Help or More Information?

Questions about this free C programming course, embedded C training or career guidance? Get in touch.

MODULE 7 · LESSON 7.3 · PRACTICE

Break and Continue Interview Questions for Embedded C: Quiz and Code Challenges

57 questions: multiple choice, write-the-statement blanks, a technique-matching table, true/false, 6 code challenges with real output and 12 detailed interview answers. Treat it as a model for break and continue interview questions.

57
Questions
Beginner → Advanced
Level
Live score
Auto-graded
Live Score Tracker
0
Correct
0
Wrong
0
Attempted
Answer the auto-graded questions (MCQ, fill-in, true/false) to see your score.

Section 1: Multiple Choice Questions — break, continue and Nested Loops

These break and continue interview questions in multiple-choice form are common in written screening tests. Click an answer; explanations always appear.

1. What does break do inside a for loop?

2. What does continue do inside a for loop?

3. In a while loop, continue jumps to:

4. Which problem can occur with continue in a while loop?

5. How many times does the inner body run: for (i=0;i<5;i++) for (j=0;j<4;j++)?

6. How many times does the inner body run: for (i=0;i<4;i++) for (j=0;j<=i;j++)?

7. Which statement leaves a switch inside a loop but not the loop?

8. Which way leaves two nested loops without goto?

9. Which index belongs in the inner loop for a C array int m[R][C]?

10. MISRA C:2012 rule 15.4 recommends:

11. Which use of goto is widely accepted in C?

12. What happens in for (;;) { if (x) break; } when x becomes true?

13. After for (i = 0; i < n; i++) if (a[i] == key) break; how do you know the key was found?

14. What is the trip count of the innermost body in a loop nest of 3, 4 and 5 passes?

15. Why do prime tests stop when d * d > n?

Section 2: Write or Evaluate (Fill in the Blanks)

Type the statement for the first three items and a short value for the rest.

1. Write the statement that leaves the innermost loop:

2. Write the statement that skips to the next pass of the loop:

3. Write the statement that jumps to a label named cleanup:

4. int c = 0; for (int i = 0; i < 6; i++) { if (i == 2) continue; c++; } gives c =

5. int c = 0; for (int i = 0; i < 6; i++) { if (i == 2) break; c++; } gives c =

6. for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) if (j == 1) break; runs the test j == 1 times in total

7. The number of pairs among 6 items (each pair once) is

8. In a loop nest 2 x 3 x 4 the innermost body runs times

Section 3: Which Statement Fits?

Choose the jump statement or technique, as asked in break and continue interview questions about design.

TaskYour answerResult
Stop searching as soon as the key is foundbreakcontinuereturngoto cleanup labelflag in the outer conditionupdate before continue
Ignore an invalid sample and take the nextbreakcontinuereturngoto cleanup labelflag in the outer conditionupdate before continue
Leave two nested loops from a helper functionbreakcontinuereturngoto cleanup labelflag in the outer conditionupdate before continue
Release resources in reverse order after a failurebreakcontinuereturngoto cleanup labelflag in the outer conditionupdate before continue
Leave a switch inside a loop but keep loopingbreakcontinuereturngoto cleanup labelflag in the outer conditionupdate before continue
Skip to the next iteration of a loop from inside a switchbreakcontinuereturngoto cleanup labelflag in the outer conditionupdate before continue
Leave two loops using a status variablebreakcontinuereturngoto cleanup labelflag in the outer conditionupdate before continue
Prevent a skipped update in a while loopbreakcontinuereturngoto cleanup labelflag in the outer conditionupdate before continue

Section 4: True or False

Statements typical of break and continue interview questions.

1. break can leave any number of nested loops at once.

2. continue in a for loop skips the update expression.

3. continue is allowed inside a switch that is inside a loop.

4. break is allowed outside any loop or switch.

5. The total passes of a nested loop with independent limits is the product.

6. A goto may jump into the middle of a block, skipping an initialiser.

7. A return inside nested loops leaves all of them.

8. A loop with an unreachable break is still an infinite loop.

Section 5: Code Snippet Challenges

Trace each program on paper first; the real output follows. These challenges are the code-reading half of break and continue interview questions.

Challenge 1 — Output?: continue then break
#include <stdio.h> int main(void) { for (int i = 0; i < 6; i++) { if (i % 2 == 0) continue; if (i == 5) break; printf(“%d “, i); } printf(“\n”); return 0; }

What is printed?

Output:
1 3 
Even numbers are skipped; odd 1 and 3 are printed; at i = 5 the break ends the loop before the printf.
Challenge 2 — Output?: Inner break depending on the outer counter
#include <stdio.h> int main(void) { int count = 0; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) { if (j > i) break; count++; } printf(“%d\n”, count); return 0; }

What is count?

Output:
10
For i = 0..3 the inner loop runs j = 0..i before breaking: 1 + 2 + 3 + 4 = 10.
Challenge 3 — Output?: continue before the update
#include <stdio.h> int main(void) { int i = 0, passes = 0; while (i < 5) { if (++passes > 12) break; if (i == 2) continue; i++; } printf(“i=%d passes=%d\n”, i, passes); return 0; }

What is printed?

Output:
i=2 passes=13
When i reaches 2 the continue skips i++, so i never changes again. The safety break stops the loop at 13 passes.
Challenge 4 — Output?: Index after break
#include <stdio.h> int main(void) { int i; for (i = 0; i < 10; i++) if (i * i > 20) break; printf(“%d\n”, i); return 0; }

What is printed?

Output:
5
5 x 5 = 25 is the first square greater than 20, so the loop breaks with i = 5.
Challenge 5 — Output?: continue inside a switch in a loop
#include <stdio.h> int main(void) { int n = 0; for (int i = 1; i <= 3; i++) { switch (i) { case 2: continue; default: n += 10; } n++; } printf(“%d\n”, n); return 0; }

What is n?

Output:
22
i = 1: default adds 10, n++ gives 11. i = 2: continue skips everything. i = 3: adds 10 giving 21, n++ gives 22.
Challenge 6 — Output?: Leaving two loops with a flag
#include <stdio.h> int main(void) { int found = 0; for (int r = 0; r < 3 && !found; r++) for (int c = 0; c < 3; c++) if (r * 3 + c == 4) { found = 1; printf(“at (%d,%d)\n”, r, c); break; } printf(“found=%d\n”, found); return 0; }

What is printed?

Output:
at (1,1)
found=1
The element number 4 is at row 1, column 1. The break leaves the inner loop and the flag stops the outer loop.

Section 6: Break and Continue Interview Questions for Embedded C (with Detailed Answers)

Break and continue interview questions test whether you can control loops precisely and write code that terminates and can be reviewed. Click a question for a model answer.

Q1. What is the difference between break and continue?Basic+

break terminates the loop (or switch) completely; continue ends only the current iteration and moves on to the next one. In a for loop continue still runs the update expression; in a while or do-while loop it jumps to the condition test.

bc_iq.c
#include <stdio.h> int main(void) { for (int i = 0; i < 5; i++) { if (i == 1) continue; if (i == 3) break; printf(“%d “, i); } printf(“\n”); return 0; }
Output (verified by compiling and running)
0 2
Q2. How do you exit from two nested loops?Intermediate+

Options: (1) a flag that the outer loop also tests; (2) move the loops into a function and return; (3) a forward goto to a label after the loops. The function-with-return version is usually the clearest and is testable on its own. A plain break only leaves the inner loop.

Q3. Is goto harmful? When is it acceptable?Intermediate+

Unstructured goto, especially backwards or into blocks, makes control flow hard to follow and is rejected by most standards. A forward goto to one cleanup label at the end of a function is a long-established pattern for releasing resources in reverse order on error, as in the Linux kernel. MISRA C:2012 still classes goto as advisory and requires that it only jumps forward within the same function (rules 15.1 to 15.3).

Q4. Why can continue cause an infinite loop in a while loop?Intermediate+

The update of the loop variable is in the body. If a continue is executed before it, the update is skipped, the condition does not change and the same iteration repeats. Fix it by updating before the continue, restructuring with if/else, or by using a for loop where the update is in the header and cannot be skipped.

Q5. What is the time complexity of nested loops and why does it matter on a microcontroller?Intermediate+

Independent nested loops multiply: 3 loops of N passes cost N cubed. On a 168 MHz Cortex-M4 N = 100 means 1 million inner-body executions, which can take several milliseconds and miss a real-time deadline. Reduce nesting, move invariant work out, or use DSP/DMA hardware. Always check the worst-case count against the available time slot.

Q6. Why is the column index the inner loop for a 2D C array?Intermediate+

C arrays are stored in row-major order, so a[r][c] and a[r][c+1] are adjacent. Iterating the column in the inner loop reads memory sequentially: it is faster with caches and prefetching (Cortex-M7), friendlier to DMA and generates simpler address arithmetic (a post-increment load) on the Cortex-M4.

rowmajor_iq.c
#include <stdio.h> int main(void) { int a[2][3]; printf(“%d %d\n”, (int)((char *)&a[0][1] – (char *)&a[0][0]), (int)((char *)&a[1][0] – (char *)&a[0][0])); return 0; }
Output (verified by compiling and running)
4 12
Q7. Rewrite a loop that uses continue so that it does not use continue. Which is better?Intermediate+
no_continue_iq.c
#include <stdio.h> int main(void) { int v[] = { 3, –1, 4, –1, 5 }; int s1 = 0, s2 = 0; for (int i = 0; i < 5; i++) { if (v[i] < 0) continue; s1 += v[i]; } for (int i = 0; i < 5; i++) { if (v[i] >= 0) { s2 += v[i]; } } printf(“%d %d\n”, s1, s2); return 0; }
Output (verified by compiling and running)
12 12

Both are correct. continue avoids one level of nesting when the normal path is long; the if-form is better when the loop body is short or when MISRA-style rules limit jump statements. Pick one style per project.

Q8. A search loop finishes and the code uses a[i] afterwards. What bug is possible?Advanced+

When the key is not found, the loop ends with i == n and a[i] is one element past the end: an out-of-bounds read or write. Always test whether the loop ended by break (for example if (i < n)) or use a separate found index initialised to -1 and set before the break.

Q9. How would you restart a loop from the beginning without goto?Advanced+

Wrap it in an outer loop with a flag: do { restart = 0; for (...) { if (cond) { restart = 1; break; } } } while (restart);, or place the loop in a function that returns a status and call it again. Make sure that a bound limits the number of restarts, otherwise a persistent condition causes an infinite loop.

Q10. How do break and continue affect worst-case execution time analysis?Advanced+

Each exit adds a path. The analyser must still find a bound on the loop count, and the early exit can only shorten the time. For safety-critical code the worst case is the longest path (no early exit), which is the value that must meet the deadline. Too many exits make the control-flow graph harder to analyse and review, which is why MISRA recommends a single exit per loop.

Q11. What does the compiler do with a loop that has a break at the very end of the body?Advanced+

A loop whose body always ends with an unconditional break executes at most once; GCC recognises this at -O1 and above and removes the loop, leaving an if statement. Static analysers report such code as suspicious (unreachable back edge), which usually means a missing condition.

Q12. Implement bounded retries with a delay using break and a for loop.Advanced+
retry_iq.c
#include <stdio.h> #include <stdbool.h> static int calls; static bool read_sensor(int *out) { calls++; if (calls < 3) return false; *out = 42; return true; } int main(void) { int value = –1; int attempt; for (attempt = 1; attempt <= 5; attempt++) { if (read_sensor(&value)) break; /* success: stop retrying */ printf(“attempt %d failed, waiting\n”, attempt); /* delay_ms(10); on the target */ } if (attempt > 5) printf(“sensor failed after 5 attempts\n”); else printf(“sensor ok after %d attempts, value=%d\n”, attempt, value); return 0; }
Output (verified by compiling and running)
attempt 1 failed, waiting attempt 2 failed, waiting sensor ok after 3 attempts, value=42

The index after the loop tells which way it ended: attempt > 5 means every try failed. A fixed maximum number of attempts makes the worst-case time known.

Study Plan: Using Your Score on These Break and Continue Interview Questions

ScoreMeaningNext step
90–100%ExcellentContinue to Module 8: functions.
70–89%GoodRedo Examples 2, 5 and 8 of this lesson.
Below 70%ReviseRe-read theory sections 1–5, then retake the quiz.
Habit to build: For each loop with a break, write down the value of the loop variable after a normal exit and after the break, and check that the code after the loop handles both.

Module 7 complete!

Next up: Module 8, functions: declarations, parameters, scope, recursion and function pointers.

Need Help or More Information?

Questions about this free C programming course, embedded C training or career guidance? Get in touch.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *