Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to stop the loop when the number is 5.
Bash Scripting
for i in {1..10}; do if [ "$i" -eq 5 ]; then [1] fi echo "$i" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'continue' instead of 'break' which skips the current iteration but does not stop the loop.
✗ Incorrect
The 'break' command stops the loop immediately when the condition is met.
2fill in blank
mediumComplete the code to skip printing the number 3 but continue the loop.
Bash Scripting
for i in {1..5}; do if [ "$i" -eq 3 ]; then [1] fi echo "$i" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' which stops the loop instead of skipping one iteration.
✗ Incorrect
The 'continue' command skips the current iteration and continues with the next one.
3fill in blank
hardFix the error in the code to correctly skip even numbers and print only odd numbers.
Bash Scripting
for num in {1..6}; do if [ $((num % 2)) -eq 0 ]; then [1] fi echo "$num" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' which stops the loop instead of skipping even numbers.
✗ Incorrect
Using 'continue' skips even numbers and prints only odd numbers.
4fill in blank
hardFill both blanks to stop the loop when number is 4 and skip printing number 2.
Bash Scripting
for n in {1..5}; do if [ "$n" -eq 2 ]; then [1] fi if [ "$n" -eq 4 ]; then [2] fi echo "$n" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' to skip number 2 which stops the loop too early.
Using 'continue' to stop the loop which only skips iterations.
✗ Incorrect
Use 'continue' to skip printing 2 and 'break' to stop the loop at 4.
5fill in blank
hardFill all three blanks to skip number 3, stop at number 6, and print the rest.
Bash Scripting
for val in {1..7}; do if [ "$val" -eq 3 ]; then [1] fi if [ "$val" -eq 6 ]; then [2] fi echo "$val" done # After loop ends [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' to skip number 3 which stops the loop early.
Using 'exit' after the loop which ends the script abruptly.
✗ Incorrect
Use 'continue' to skip 3, 'break' to stop at 6, and print a message after the loop.