Difference between continue and break in shell

Source: Internet
Author: User
The break command can contain one parameter. A break loop without a parameter can only exit the innermost loop, while breakN can exit the N-layer loop. The continue command can also contain a parameter. A continue command without a parameter only removes the remaining code of this loop, while continueN removes all the remaining code of the N-tier loop, but the number of cycles remains unchanged. #! /Bin/shforiin & quot; abcd & quot; do &

The break command can contain one parameter. A break loop without a parameter can only exit the innermost loop, while break N can exit the N-layer loop.
The continue command can also contain a parameter. A continue command without a parameter only removes the remaining code of this loop, while continue N removes all the remaining code of the N-tier loop, but the number of cycles remains unchanged.

 
 
  1. #!/bin/sh  

  2. for i in"a b c d"

  3. do  

  4.  echo "$i "

  5. for j in `seq 10`  

  6.    do  

  7.      if [ $j -eq 5 ];then

  8. break  

  9.      fi  

  10.      echo "$j "

  11.    done

  12.  echo      

  13. done  

Break result:
A 1 2 3 4
B 1 2 3 4
C 1 2 3 4
D 1 2 3 4
Result of break 2:
A 1 2 3 4
Continue result:
A 1 2 3 4 6 7 8 9 10
B 1 2 3 4 6 7 8 9 10
C 1 2 3 4 6 7 8 9 10
D 1 2 3 4 6 7 8 9 10
Result of continue 2:
A 1 2 3 4
B 1 2 3 4
C 1 2 3 4
D 1 2 3 4


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.