In Unix/Linux, you can use a for
loop to iterate through a range of numbers from 1 to 100. Here’s how to do it:
- Open a terminal window.
- Type the following command to start the
for
loop:
for i in {1..100}
This will set up the for
loop to iterate through the numbers 1 to 100.
- Type the commands that you want to execute inside the loop. For example, to print each number to the screen, you can use the
echo
command:
for i in {1..100}
do
echo $i
done
This will print the numbers 1 to 100 to the screen, each on its own line.
- When you’re finished with the loop, type
done
to exit the loop:
for i in {1..100}
do
echo $i
done
This will execute the loop and print the numbers 1 to 100 to the screen.
Note that the curly braces in the for
loop syntax are used to define the range of numbers to iterate through. You can adjust the range to suit your needs. For example, to iterate through numbers from 10 to 20, you can use the following syntax:
for i in {10..20}
do
echo $i
done