1、while loop

Yes while Circularly speaking , As long as the conditional judgment holds , The cycle goes on and on , Until the conditional judgment doesn't hold , The cycle stops . and for The second form of the loop for(( Initial value ; Cycle control conditions ; Variable change )) similar .

We write a 1 Add to 100 Example , Although this kind of example is of little help to system management , But it's very helpful to understand the loop :

while Cyclic syntax format :

while [  Conditional judgment  ]
do
Program
done

Example :1 Add to 100.

#!/bin/bash

#  To the variable i And variables s assignment 
# from 1 Start adding
i=1
# Summation variables
sum=0 # perform while Circle sum
# If the variable i Is less than or equal to 100, Then execute the loop
while [ $i -le 100 ]
do
sum=$(( $sum+$i ))
i=$(( $i+1 ))
done # Output summation result
echo "The sum is:$sum"

explain :

while The cycle is Shell There are still very few scripts , Recycling main use for The first form of the loop for Variable in value 1 value 2 value 3 …, So we can understand it .

and while Loop in writing algorithm , It will be very convenient. .

2、until loop

until Circulation and while The cycle is reversed ,until As long as the conditional judgment does not hold, the loop will be carried out , And execute the loop program .

Once the cyclic condition is established , Then stop the cycle .

The grammar is as follows :

until [  Conditional judgment  ]
do
Program
done

Or write from 1 Add to 100 This example , Pay attention to and while Difference between cycles :

#!/bin/bash

#  To the variable i And variables s assignment 
# from 1 Start adding
i=1
# Summation variables
sum=0 # perform while Circle sum
# If the variable i The value is greater than 100, Then execute the loop
until [ $i -gt 100 ]
do
sum=$(( $sum+$i ))
i=$(( $i+1 ))
done # Output summation result
echo "The sum is:$sum"

summary :

while Circulation and until Loops are especially easy to write as dead loops , Forgot to write variable changes in the loop body , Such as i=i+1 perhaps i++ etc. , The judgment conditions leading to the cycle always meet the conditions , The loop can't stop , Very expensive system resources .

『 Forget to learn again 』Shell Process control — 38、while Circulation and until More related articles of circular Introduction

  1. 『 Forget to learn again 』Shell Basics — 1、Shell Introduction to

    Catalog 1.Shell The origin of 2.Shell Two ways of executing instructions 3. What is? Shell Script 4.Shell Is a scripting language 1.Shell The origin of We are familiar with Windows Graphical interface of the system , For graphical interfaces ...

  2. 『 Forget to learn again 』Shell Basics — 10、Bash Special symbols in ( Two )

    Tips : This article is followed by an article , Mainly about () Parentheses and {} The difference and use of braces . 8.() parentheses (): Used when a series of commands are executed ,() The command in will be in the sub Shell Run in .( Together with the braces below ) 9.{} Curly braces {}: ...

  3. 『 Forget to learn again 』Shell Basics — 3、echo Introduction and use of command

    Catalog 1.echo Role of command 2.echo Basic usage of commands 3.echo Ordered -e Option usage 4.echo Some special uses of commands (1) The output character has a font color (2) The output character has a background color Talking about Shell Before the script , ...

  4. 『 Forget to learn again 』Shell Basics — 4、Bash Basic function (history command )

    Catalog 1.history History commands 2. Set the number of command history records 3. Clear history command 4. Call of history command 5. Completion of commands and files stay Linux Default... In the system Shell Namely Bourne-AgainShell( abbreviation ...

  5. 『 Forget to learn again 』Shell Basics — 9、Bash Special symbols in ( One )

    Catalog 1. Double single quotation mark 2. Double quotes 3.$ Symbol 4. The quotation marks 5.$() Symbol 6.# Symbol 7.\ Symbol 1. Double single quotation mark '': Single quotation marks . All special symbols in single quotation marks , Such as $ and "`"( The quotation marks ) Nothing special ...

  6. 『 Forget to learn again 』Shell Basics — 11、 Rules and classification of variable definition

    Catalog 1. Rules for defining variables 2. Classification of variables 1. Rules for defining variables When you define variables , There are some rules to follow Variable names can be alphabetized . Numbers and underscores , But it can't start with a number . If the variable name is 2name It's wrong . stay Bash ...

  7. 『 Forget to learn again 』Shell Basics — 2、Shell Function and classification of

    Catalog 1.Shell The role of 2.Shell The classification of 1.Shell The role of Shell In addition to being able to interpret user input commands , Pass it to the kernel , just so so : Call other programs , Passing data or parameters to other programs , And get the processing result of the program . stay ...

  8. 『 Forget to learn again 』Shell Basics — 5、Bash Basic function ( Command aliases and common shortcuts )

    Catalog 1. Alias the command (1) Format the alias command (2) The command alias takes effect permanently (3) Alias priority 2.Bash Common shortcut key 1. Alias the command Linux The command alias of the system, as we have said before , Go over here . ...

  9. 『 Forget to learn again 』Shell Basics — 6、Bash Basic function ( I / O redirection )

    Catalog 1.Bash Standard input and output of 2. Output redirection (1) Standard output redirection (2) Standard error output redirection (3) Correct output and error output are saved at the same time 3. Input redirection 1.Bash Standard input and output of We've been talking about , stay Li ...

  10. 『 Forget to learn again 』Shell Basics — 8、 Introduction to pipeline symbols

    We've already written about pipe symbols before , Today, let's briefly summarize the usage . 1. Line extraction command grep grep Role of command , Is in the specified file , Search for qualified strings . Command format : [[email protected] ~ ] ...

Random recommendation

  1. JavaScript Synchronization and asynchrony of

    1. Draw a picture by hand to illustrate . 2. Why? JavaScript A single thread ( Here is a quote from Mr. Ruan Yifeng ) JavaScript The single thread , Related to its use . As a browser scripting language ,JavaScript Its main purpose is to interact with users , ...

  2. win7 install JDK7 and JDK8 after , uninstall JDK8 Error after

    This is my study Java Some problems encountered in the process and solutions , Record here , It is convenient for me to view , Solve other people's doubts . I am win7 x64 Flagship Edition , At the same time installed JDK7 and JDK8, Uninstalled JDK8 after ,cmd Command line input :java - ...

  3. Codeforces Round #371 (Div. 2) - B

    Topic link :http://codeforces.com/contest/714/problem/B The question : Given a length of N The initial sequence of , Then ask if you can find a value x, Then make each element of the sequence +x/-x/ unchanged , most ...

  4. Talk about cloud computing and SOA (1)

    SOA What is it? ? English literal translation is a service-based architecture , Is a technical framework , Make all relevant systems inside and outside the enterprise open and access well-defined services and information bound to services , It is further abstracted into process layer and composite application , To form a solution . Say something reasonable. : Reuse service ...

  5. django Integrate microblog content

    Log in to Weibo My tools OK. Share sns The website URL shared . Go to the above to get the code . It is called Weibo show after revision

  6. Mysql Basic structure and query process

    mysql A brief overview of the architecture : Connectors: Access party , There are a lot of support agreements Management Serveices & Utilities: System management and control tools such as : Backup recovery ,mysql Replication cluster ...

  7. Linux Next, forget MySQL Password solutions and input mysqld_safe --skip-grant-tables & I can't get into MySQL Solutions for

    stay Linux Next, forget MySQL After the password, we can pass a mysql Parameters of --skip-grant-tables & It's easy to solve this problem The test is in CentOS It works among --skip-grant-table ...

  8. 01- Use eclipse Create a new standard java web project

    1. Use eclipse Create a normal Java SE project   name :CRM java web Standard structure catalog crm WEB-INF classes lib web.xml Set project bytecode output directory

  9. Simple and thorough understanding JSONP Principle and use

    Let's start with JSON The concept ,JSON Is a lightweight data transfer format , Is widely used in the present Web Application .JSON The encoding and parsing of format data are basically implemented in all mainstream languages , So now most of the front-end and back-end separation architectures use JSON Format advance ...

  10. Participate in .net Open source project development

    EntityFramework6 https://github.com/aspnet/EntityFramework6 https://github.com/aspnet/EntityFramewor ...