continue

Sometimes you will find yourself in the middle of the code block, and you need to say, Forget the rest of this run through the code block and start the next run through the code block. This is done with the continue command. For example, what if you were pretty sure that no multiples of 3 satisfied the equation? How would you avoid wasting precious time checking those?

#​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​+​+​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​i​f​ ​(​i​ ​%​ ​3​ ​=​=​ ​0​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​c​o​n​t​i​n​u​e​;​
 ​ ​ ​ ​ ​ ​ ​ ​}​
 ​ ​ ​ ​ ​ ​ ​ ​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​ ​a​n​s​w​e​r​ ​i​s​ ​%​d​.​​n​"​,​ ​i​)​;​
 ​ ​ ​ ​r​e​t​u​r​n​ ​0​;​
}​

Build and run it:

C​h​e​c​k​i​n​g​ ​i​ ​=​ ​1​
C​h​e​c​k​i​n​g​ ​i​ ​=​ ​2​
C​h​e​c​k​i​n​g​ ​i​ ​=​ ​4​
C​h​e​c​k​i​n​g​ ​i​ ​=​ ​5​
C​h​e​c​k​i​n​g​ ​i​ ​=​ ​7​
C​h​e​c​k​i​n​g​ ​i​ ​=​ ​8​
C​h​e​c​k​i​n​g​ ​i​ ​=​ ​1​0​
T​h​e​ ​a​n​s​w​e​r​ ​i​s​ ​1​0​.​

Figure 7.4  continue

continue
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset