课程: Learning Linux Shell Scripting
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Using break and continue
- [Instructor] Both loops import two special instructions, break and continue. Break causes the current loop to terminate and it begins executing the instructions after the done statement. Let's try it out. We'll add an if statement in the loop before printing the current name. So, here we'll put our if and we'll say $NAME equals Tracy and make sure we got a space before the square bracket. Then, and we'll put a break. And then we'll put the fi. We'll save this off with a control S. Go back to the terminal. Once again, we'll type in Stacy, Tracy and Lacy and you notice what we get. Now we get the hello Stacy and as soon as it detects the Tracy, the break statement causes it to stop execution of the loop and the loop gets terminated and we exit our program. The continue statement goes immediately to the top of the loop. Let's replace the break with continue and see what happens. So, here we'll change break to continue. We'll save this off with a control S. Go to the terminal. Once…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。