Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print numbers from 1 to 5 using a C-style for loop in bash.
Bash Scripting
for (( i=1; i<=5; i[1] )); do echo $i done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--' which decreases the variable.
Using '+' or '*' which are not valid increment operators in this syntax.
✗ Incorrect
The increment operator '++' increases the variable i by 1 each loop iteration.
2fill in blank
mediumComplete the code to print numbers from 10 down to 1 using a C-style for loop in bash.
Bash Scripting
for (( i=10; i[1]1; i-- )); do echo $i done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' which would not work for counting down.
Using '>' which would cause the loop to never run.
✗ Incorrect
The loop continues while i is greater than or equal to 1.
3fill in blank
hardFix the error in the loop condition to print numbers from 0 to 4.
Bash Scripting
for (( i=0; i[1]5; i++ )); do echo $i done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causes the loop to print 5, which is not desired.
Using '>' or '>=' causes the loop to never run.
✗ Incorrect
The loop should run while i is less than 5 to print 0 through 4.
4fill in blank
hardFill both blanks to create a loop that prints even numbers from 2 to 10.
Bash Scripting
for (( i=[1]; i[2]10; i+=2 )); do echo $i done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 prints odd numbers.
Using '<' excludes 10 from the output.
✗ Incorrect
Start at 2 and continue while i is less than or equal to 10, incrementing by 2.
5fill in blank
hardFill all three blanks to create a loop that prints numbers from 5 down to 0.
Bash Scripting
for (( [1]=5; [2][3]0; [1]-- )); do echo $[1] done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in initialization and condition.
Using '>' excludes 0 from the output.
✗ Incorrect
Use variable i, loop while i is greater than or equal to 0, and decrement i each time.