break

Sometimes it is necessary to stop the loop’s execution from inside the loop. For example, let’s say you want to step through the positive integers looking for the number x, where x + 90 = x2. Your plan is to step through the integers 0 through 11 and pop out of the loop when you find the solution. Change the code:

#​i​n​c​l​u​d​e​ ​<​s​t​d​i​o​.​h​>​

i​n​t​ ​m​a​i​n​(​i​n​t​ ​a​r​g​c​,​ ​c​o​n​s​t​ ​c​h​a​r​ ​*​ ​a​r​g​v​[​]​)​
{​
 ​ ​ ​ ​i​n​t​ ​i​;​
 ​ ​ ​ ​f​o​r​ ​(​i​ ​=​ ​0​;​ ​i​ ​<​ ​1​2​;​ ​i​+​+​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​p​r​i​n​t​f​(​"​C​h​e​c​k​i​n​g​ ​i​ ​=​ ​%​d​\​n​"​,​ ​i​)​;​ ​ ​ ​ ​ ​ ​ ​ ​i​f​ ​(​i​ ​+​ ​9​0​ ​=​=​ ​i​ ​*​ ​i​)​ ​{​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​b​r​e​a​k​;​ ​ ​ ​ ​ ​ ​ ​ ​}​ ​ ​ ​ ​}​ ​ ​ ​ ​p​r​i​n​t​f​(​"​T​h​e​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.