break, continue

Assalamu Alaikum. Hope, you all are well by the grace of almighty ALLAH. Today we learn about the break and continue statement.


The break statement will immediately jump to the end of the current block of code. To exit a loop we can use the break statement any time. This can be very useful if we want to stop running a loop because a condition has been met other than the loop end condition. Take a look at the following example:

In the example above, the for loop will run , as long i is smaller than 10.In the for loop there is an if statement  that states that if i equals six the for loop must stop(break).


The continue statement will skip the rest of the code in the current loop block and return to the evaluation part of the loop. Take a look at the example below:

In the example above, we skip the number five in our countdown.
Take a look at another example.

In the example above the printf function is never called because of the "continue".

Thank you all..:)


Post a Comment