Cycle (for, while, until) circulating the control characters (break, continue)

A, for circulation

The first style for ((;;;)) (C-like style)

                      do

                  command

                  done

 

例子:for ((i=0;i<10;i++))

           do

           echo $i

           done

 

The second style for variable in {list}

                      do

                    command

                     done

 

Examples: for i in {1..10..2} // print the odd-numbered 1-10.

           do

           echo $i

           done

 

           a = (1 2 3 9 8 60 625) // array a defined

           for i in $ {a [*]} // iterate

             do

           echo $i

           done

 

Two, while circulation

while expression

do

command

done

 

Examples (Print 0-10): a = 0

           while [ a -ge  10 ]

             do

             echo $ a

              let "a++"

             done

 

 

           while (( a >=10))     

             do

             echo $ a

              let "a++"

             done

 

Two, until the cycle

And while similar, while only condition is satisfied before the implementation of the loop, until only the conditions are not established before the implementation of the loop)

 

Three, break

Force Quit for loop

 

example:

sum=0

for((i=1;i<=100;i++))

do

let "sum=sum+i"

if [ sum -gt 1000 ]

then

echo "1+2+..+$i=$sum"

break

be

done

 

Four, continue

Skip this statement following the loop, the next execution cycle

 

Guess you like

Origin www.cnblogs.com/97lzc/p/11256176.html