0
0
Bash Scriptingscripting~10 mins

for loop with range ({1..10}) in Bash Scripting - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - for loop with range ({1..10})
Start
Set range 1 to 10
Pick next number in range
Execute loop body with number
More numbers?
YesPick next number
No
End loop
The loop picks each number from 1 to 10 in order, runs the commands inside the loop for each number, then stops after 10.
Execution Sample
Bash Scripting
for i in {1..10}; do
  echo $i
done
Print numbers from 1 to 10, one per line.
Execution Table
Iterationi valueActionOutput
11echo $i1
22echo $i2
33echo $i3
44echo $i4
55echo $i5
66echo $i6
77echo $i7
88echo $i8
99echo $i9
1010echo $i10
--No more numbers in rangeLoop ends
💡 After printing 10, no more numbers in the range {1..10}, so loop stops.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6After 7After 8After 9After 10Final
iundefined12345678910undefined
Key Moments - 2 Insights
Why does the loop stop after printing 10?
Because the range {1..10} only includes numbers from 1 to 10. After 10, there are no more numbers to pick, so the loop ends as shown in the last row of the execution_table.
What happens if you change {1..10} to {3..5}?
The loop will only run for i=3, 4, and 5. The execution_table would have only three iterations instead of ten.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of i at iteration 5?
A6
B5
C4
D10
💡 Hint
Check the 'i value' column in the execution_table at iteration 5.
At which iteration does the loop stop running?
AAfter iteration 9
BAfter iteration 1
CAfter iteration 10
DIt never stops
💡 Hint
Look at the exit_note and the last row of the execution_table.
If the range changes to {1..3}, how many iterations will the loop run?
A3
B10
C1
D0
💡 Hint
The range {1..3} means numbers 1, 2, and 3 only, so check the variable_tracker for how many values i takes.
Concept Snapshot
for i in {start..end}; do
  commands using $i
 done

- Loops over numbers from start to end
- Runs commands once per number
- Stops after last number
- Simple way to repeat tasks with numbers
Full Transcript
This visual execution shows how a bash for loop with a range {1..10} works. The loop picks each number from 1 to 10 in order. For each number, it runs the commands inside the loop body. Here, it prints the number. The execution table lists each iteration with the current value of i and the output. The variable tracker shows how i changes from undefined to 1, then 2, up to 10, then back to undefined after the loop ends. Key moments explain why the loop stops after 10 and what happens if the range changes. The quiz questions test understanding of the loop variable values, when the loop stops, and how changing the range affects iterations.