课程: Complete Guide to C Programming Foundations

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

Breaking out of a loop

Breaking out of a loop

- [Instructor] A loop repeats its statements until the terminating condition is met or until a break statement is encountered. In this code, input from the user is requested. The loop repeats based on the value input or until the value of variable A reaches nine, run. I'm going to try a huge value like 300, but you see the loop only repeats 10 times. The IF statement at line 12 tests to see when the value of variable A is equal to nine. If so, its sole statement break is executed, the loop is broken, and execution continues outside the loops block. When used in a nested loop break halts only the loop it sits in here, you see nested for loops. At line 13 an if test is made, if variable column is equal to the letter E, the inner loop is broken run, and the table stops output at all rows after letter E, only the inner loop is affected. You can use break to avoid entangling your code in an endless loop. Here, the while loops condition is one, true. The loop has no exit condition except…

内容