Answer to Question #292724 in UNIX/Linux Programming for Lavu

Question #292724

Write a shell script using Nested for loops of your own and explain each statement of that script. Explanation



1
Expert's answer
2022-02-05T02:04:21-0500
#!/bin/bash
# A shell script to print each number five times.
for (( i = 1; i <= 5; i++ ))      ### Outer for loop ###
do 
   for (( j = 1 ; j <= 5; j++ )) ### Inner for loop ###   
 do     
     echo -n "$i "   
 done  echo "" #### print the new line ###
done
Explanation
For each value of i the inner loop is cycled through 5 times, with the variable j taking values from 1 to 5. The inner for loop terminates when the value of j exceeds 5, and the outer loop terminates when the value of i exceeds 5.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS