loop control statements in c

Hello coders! Welcome back!

Today will look into the loop controlling statements.

  1. break 
  2. continue 

1] Break- 

A break is used to terminate a loop. 

Let's look into code-  

We have seen this in the previous blog (click here to view)
If break instruction was not mentioned, then subsequent instruction would have been evaluated. And we won't get the desired output.

2] continue- 

Continue statement is similar to break. 
In the break, we are completely terminating the loop.
In continue statement, we are forcing it to execute the next iterations of the loop.

let's look into the code- 

Here we are trying to print numbers that are divisible between 1 to 8 by 2. 
The numbers which are divisible by 2 are printed 
If not, in else statement we have mentioned 'continue' instruction. 
Continue instruction just increment the value of 'n' and then we repeat the loop until the condition is satisfied. 

This is it for this blog! Seems very short but very important statements used by programmers. If any doubt please comment without any hesitation. Always ready to clear your doubts. 

Happy learning!

Comments

Popular post