Bird
0
0

How can you use break and continue together to print numbers 1 to 10 but stop the loop if number is greater than 7 and skip printing 5?

hard🚀 Application Q9 of 15
Bash Scripting - Loops
How can you use break and continue together to print numbers 1 to 10 but stop the loop if number is greater than 7 and skip printing 5?
Afor i in {1..10}; do if (( i > 7 )); then break; elif (( i == 5 )); then continue; fi; echo $i; done
Bfor i in {1..10}; do if (( i == 5 )); then break; elif (( i > 7 )); then continue; fi; echo $i; done
Cfor i in {1..10}; do if (( i > 7 )); then continue; elif (( i == 5 )); then break; fi; echo $i; done
Dfor i in {1..10}; do if (( i == 5 )); then continue; elif (( i == 7 )); then break; fi; echo $i; done
Step-by-Step Solution
Solution:
  1. Step 1: Understand conditions for break and continue

    Break stops loop if number > 7. Continue skips printing 5.
  2. Step 2: Check option logic

    for i in {1..10}; do if (( i > 7 )); then break; elif (( i == 5 )); then continue; fi; echo $i; done correctly breaks if >7 and continues if ==5 before printing. Others swap or misuse break and continue.
  3. Final Answer:

    for i in {1..10}; do if (( i > 7 )); then break; elif (( i == 5 )); then continue; fi; echo $i; done -> Option A
  4. Quick Check:

    Break >7, continue 5 skip = A [OK]
Quick Trick: Use break for stop, continue for skip in same loop [OK]
Common Mistakes:
MISTAKES
  • Swapping break and continue conditions
  • Not using elif causing both to trigger
  • Incorrect order of conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes