Recall & Review
beginner
What does the
break command do in a Bash loop?The
break command immediately stops the loop and exits it, skipping any remaining iterations.Click to reveal answer
beginner
What is the purpose of the
continue command in a Bash loop?The
continue command skips the rest of the current loop iteration and moves to the next iteration.Click to reveal answer
intermediate
How would you use
break inside a for loop to stop when a condition is met?Inside the loop, use an
if statement to check the condition. If true, run break to exit the loop immediately.Click to reveal answer
beginner
Explain the difference between
break and continue in Bash loops.break stops the entire loop immediately. continue skips only the current iteration and continues with the next one.Click to reveal answer
advanced
Can
break and continue be used in nested loops in Bash? How?Yes.
break and continue affect only the innermost loop by default. You can specify a number to affect outer loops, e.g., break 2 breaks two loops.Click to reveal answer
What happens when
break is executed inside a Bash loop?✗ Incorrect
break stops the loop immediately and exits it.Which command skips the rest of the current loop iteration and moves to the next one?
✗ Incorrect
continue skips the rest of the current iteration and proceeds to the next.In a nested loop, what does
break 2 do?✗ Incorrect
break 2 exits two nested loops at once.What will this script print?<br>
for i in 1 2 3; do
if [ "$i" -eq 2 ]; then
continue
fi
echo $i
done✗ Incorrect
When i equals 2,
continue skips printing it, so only 1 and 3 print.Which command would you use to stop a loop immediately when a condition is met?
✗ Incorrect
break stops the loop immediately.Describe how
break and continue control the flow inside Bash loops.Think about what happens to the loop after each command runs.
You got /3 concepts.
Explain how to use
break and continue in nested loops in Bash.Consider how many loops you want to exit or skip.
You got /3 concepts.