Bird
0
0

What will be the output of this script?

medium📝 Predict Output Q5 of 15
Bash Scripting - Loops
What will be the output of this script?
for i in 1 2 3 4 5; do
  if [ "$i" -eq 3 ]; then
    continue
  fi
  echo $i
done
A1 2 3 4 5
B1 2
C3
D1 2 4 5
Step-by-Step Solution
Solution:
  1. Step 1: Understand continue effect in the loop

    When i equals 3, continue skips the rest of that iteration, so echo $i is not run for 3.
  2. Step 2: Identify printed values

    All values except 3 are printed: 1, 2, 4, 5.
  3. Final Answer:

    1 2 4 5 -> Option D
  4. Quick Check:

    continue skips printing 3 = B [OK]
Quick Trick: Continue skips current iteration output [OK]
Common Mistakes:
MISTAKES
  • Thinking continue stops the loop
  • Expecting 3 to be printed
  • Confusing continue with break

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes