当前位置:网站首页>Shell script explanation (IV) -- while loop and until loop of loop statements (additional examples and analysis)

Shell script explanation (IV) -- while loop and until loop of loop statements (additional examples and analysis)

2022-06-22 19:26:00 Be the best Messi

One 、while loop

1、 Loop structure

Test a condition repeatedly , As long as the conditions are met , And then it goes back and forth , If the condition does not hold, exit the loop ( and until The cycle is reversed )

Two 、until loop  

1、 Loop structure

Test a condition repeatedly , As long as the conditions are not established , And then it goes back and forth , If the condition holds, exit the cycle

  Example (until loop )

  Calculate from 1 To 100 The sum of all integers

 

 while loop

①、 Batch add users

  •   The user name is stu start , Number in order
  •   Add all together 20 Users , namely stu1、stu2、stu3…stu20
  •   The initial password is set to 123456

 

 

 ②、 Guess the number game

  • Through the variable RANDOM get 0-999 Between random integers
  •   Prompt the user to guess , And record the number of times
  •   If the guessed number is too large or too small, the user will be prompted , Guess right to exit the loop

 

 

③、 Calculate from 1 To 100 The sum of all integers

 

 

 ④、 Filter out from 1 To 100 Odd even number of all integers

 

⑤、 Prompt the user to enter a value less than 100 The integer of , And calculate from 1 The sum of all integers between and

 

 

⑥、 Seek from 1 To 100 The even sum of all integers 、 Odd and

 

 

 ⑦、 Detect whether the specified range hosts communicate , And will communicate with the host ip output to a file host_ip in

 

Catalog

One 、while loop

1、 Loop structure

Two 、until loop  

1、 Loop structure

  Example (until loop )

  Calculate from 1 To 100 The sum of all integers

 while loop

①、 Batch add users

 ②、 Guess the number game

③、 Calculate from 1 To 100 The sum of all integers

 ​

 ④、 Filter out from 1 To 100 Odd even number of all integers

⑤、 Prompt the user to enter a value less than 100 The integer of , And calculate from 1 The sum of all integers between and

⑥、 Seek from 1 To 100 The even sum of all integers 、 Odd and

 ⑦、 Detect whether the specified range hosts communicate , And will communicate with the host ip output to a file host_ip in


原网站

版权声明
本文为[Be the best Messi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221754550494.html