Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the break command in Linux

Shulou Source: shulou.com Published: 2022-06-02 00:46:11 10月02日 Update

This article is about how to use the break command in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Common Linux commands-break commands are mainly used to end for,while or until loops

Break ends the for,while or until loop.

Summary break [n] the main purpose is to end the for,while or until loop, and several layers of loops can be specified to exit.

Parameter n (optional): an integer greater than or equal to 1 that specifies how many layers of loop to exit.

The return value returns success unless n is less than 1.

The default value of the optional parameter n for example # break is 1. # continue execution from the outer for loop. For ((item3safi > 0positanimuri -); do for ((juni3Shij > 0positjmura -)); do if ((jackfruit 2)); then # instead of break 1 results the same break fi printf "% s% s\ n" ${I} ${j} done done # output result 3 3 2 3 1 3 # when n is 2: # exit the two-tier loop and end. For ((item3persi > 0positsu -)); do for ((juni3witj > 0positjmure -)); do if ((jacks 2)); then break 2 fi printf "% s% s\ n" ${I} ${j} done done # output result 3 3 Note this command is a bash built-in command, for related help, please see the help command.

Thank you for reading! This is the end of this article on "how to use break commands in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Commands loops results content parameters more articles help output good practical successful examples information outer layers commonly used integers articles summaries uses Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft MySQL OPPO Reno Shulou Information