Showing posts with label goto. Show all posts
Showing posts with label goto. Show all posts

Saturday, 1 October 2016

Loop Control Statements in C Programming

Loop Control Statements  

Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.

The break statement in C programming has the following two usages:

  • When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
  • It can be used to terminate a case in the switch statement.

If you are using nested loops, the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.

Syntax
 Flow chart
 Example
Continue Statement

The continue statement in C programming works somewhat like the break statement.
Instead of forcing termination, it forces the next iteration of the loop to take place,skipping any code in between.

For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control to pass to the conditional tests.

Syntax 
 Flow chart

Goto statements:-

A goto statement in C programming provides an unconditional jump from the ‘goto’ to a labeled statement in the same function.

Syntax

Infinite loop

A loop becomes an infinite loop if a condition never becomes false. The for loop is traditionally used for this purpose. Since none of the three expressions that form the ‘for’ loop are required, you can make an endless loop by leaving the conditional expression empty.