Looping and Skipping

Problem Statement

for loops in Bash can be used in several ways:
– iterating between two integers, a and b
– iterating between two integers, a and b, and incrementing by c each time
– iterating through the elements of an array, etc.

Your task is to use for loops to display only odd natural numbers from 1 to 99.

Input
There is no input.

Output

1
3
5
.
.
.
.
.
99  

Recommended Resources

A quick but useful tutorial for bash newcomers is here.
Handling input is documented and explained quite well on this page.
Different ways in which for loops may be used are explained with examples here.

Solution

  
for (( c=1; c<=100; c+=2 ))
do
   echo "$c"
done

Leave a Reply