Monday, May 23, 2022

Bash Scripting 9

 Loops in Bash






Uses of Loop:
  • In programming,We need to repeat certain steps for number of times.
  • We can't repeat the statement or copy paste the code.
  • To do such thing loops where used.
  • It is used to repeat certain steps for number of times until the condition given gets failed.
  • There are three loop statement in bash:
    • while loop
    • until loop
    • for loop
While loop :
  • Syntax:

  • The loop start execute once the condition is true,else the loop end.
  • Example:


Until loop :
  • The until loop work in the reverse principle of while loop.
  • It execute the statement in the loop until the statement is false.
  • Once it reaches true,the loop terminates.
  • Syntax:

  • Example:


For loop:
  • There are various method to execute for loop.
    • One is by mentioning the range of value that are to be printed using some format
    • Example:
       


    • Another method is similar to c, c++,java,...
    • Example:


No comments:

Post a Comment

Google Cybersecurity Professional Certificate

    Google Cybersecurity Professional Certification 🔒 Google Cybersecurity Professional Certification: A Journey Unveiled! 🔒 Hey Folks! 🌟...