Shell Learning Path: Process Control (while)

Source: Internet
Author: User

While Loop :

Description: The while loop is an indeterminate loop, also known as a conditional loop. As long as the condition is judged, the loop will continue to execute until the condition is judged, and the loop will stop, which is not the same as for the fixed loop,

1  while [conditional judgment] 2      Do 3         procedure  4      Done

Example:

1[Email protected] bash]#VIWhile1.SH2#!/bin/Bash3 #从1到1004I=15s=06  while[$i-le -] ; Do7s=$ (($s +$i))8i=$ (($i +1 ))9          DoneTen Echo "The sum is: $s" One[Email protected] bash]#chmodU+x While1.SH  A[Email protected] bash]#./while1.SH  -Thesumis:5050

2.until Loop:

Description: In contrast to the while loop, the until loop is executed as long as the condition is not established, until the condition is stopped

1[Email protected] bash]#VINutil1.SH2#!/bin/Bash3I=14s=05 until[$i-GT - ]6          Do7s=$ (($s +$i))8i=$ (($i +1 ))9          DoneTen Echo "The sum is: $s" One[Email protected] bash]#chmodU+x Nutil1.SH  A[Email protected] bash]#./nutil1.SH  -Thesumis:5050

Ok

Shell Learning Path: Process Control (while)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.