x

Unix Shell loops

PREV     NEXT

Unix Shell loops:


The Loop is one of the important control statement in Unix that enables you to execute set of commands repeatedly. The following type of loops are mostly used in Unix Shell.

  • For loop
  • While loop
  • Until loop

For loop:

   For loop repeats through a set of values until the list is tired.

Ex:

Output:

To find the smallest among the given numbers using for loop,

Ex:

Output: 3

Note:

This program calculates the smallest among the numbers


While loop:

   While loops repeat statements as long as the next Unix command is successful. It works similar to the while loop in C.

Ex:

Output:

NOTE:

The value of i is tested in the while to see if it is less than or equal to 100.

Until loop:

    Until loops repeat statements until the next Unix command is successful. It Works similar to the do-while loop in C.

Ex:

Note:

The value of x is tested in the until to see if it is greater than 3.

PREV     NEXT



Like it? Please Spread the word!