Header Ad

HackerRank Looping with Numbers problem solution

In this HackerRank Looping with Numbers problem solution 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.

Use a for loop to display the natural numbers from 1 to 50.


Problem solution.

x=1
while [ $x -le 50 ]
do
    echo $x
    x=$((x+1))
done


Second solution.

for i in {1..50};do
echo $i
done


Third solution.

#!/bin/bash
for i in `seq 1 50`;
do
  echo $i
done


Post a Comment

0 Comments