0
0
Bash Scriptingscripting~10 mins

for loop with range ({1..10}) in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print numbers from 1 to 10 using a for loop.

Bash Scripting
for i in [1]; do
  echo "$i"
done
Drag options to blanks, or click blank then click option'
A<1..10>
B[1..10]
C{1..10}
D(1..10)
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or parentheses instead of curly braces.
Forgetting the two dots between numbers.
2fill in blank
medium

Complete the code to print "Number: X" for each number from 1 to 10.

Bash Scripting
for num in [1]; do
  echo "Number: $num"
done
Drag options to blanks, or click blank then click option'
A{1..10}
B[1..10]
C(1..10)
D<1..10>
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or square brackets instead of curly braces.
Missing the two dots between numbers.
3fill in blank
hard

Fix the error in the for loop to correctly iterate from 1 to 10.

Bash Scripting
for i in [1]; do
  echo $i
done
Drag options to blanks, or click blank then click option'
A{1..10}
B1..10
C[1..10]
D(1..10)
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the curly braces.
Using parentheses or square brackets instead.
4fill in blank
hard

Fill both blanks to create a loop that prints squares of numbers from 1 to 5.

Bash Scripting
for n in [1]; do
  echo $((n [2] n))
done
Drag options to blanks, or click blank then click option'
A{1..5}
B*
C+
D{1..10}
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * for multiplication.
Using wrong range like {1..10}.
5fill in blank
hard

Fill all three blanks to create a loop that prints "Number X is even" for even numbers from 2 to 10.

Bash Scripting
for num in [1]; do
  if (( num [2] 2 == 0 )); then
    echo "Number $num is [3]"
  fi
done
Drag options to blanks, or click blank then click option'
A{2..10}
B%
Ceven
D{1..10}
Attempts:
3 left
💡 Hint
Common Mistakes
Using {1..10} instead of {2..10}.
Using + instead of % for modulus.
Printing wrong word instead of 'even'.