Jump statements

The break statement

The break statement is used to exit from a loop or a switch, control passing to the first statement beyond the loop or a switch. When a break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop. A break within a loop should always be protected within an if statement which provides the state to control the exit condition. For example:

for (i =1; i <100; i ++) 
    {
        printf (“%d”, i);
        if (i = = 10) break;
    }

Prints the numbers 1 through 10 on the screen. Then the loops terminates because break causes immediate jump to the loop, overriding the conditional test i <100.


The continue statement

The is similar to brake but is encountered less frequently. Its only works within loops where its effect is to force an immediate jump to the loop control statement. instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between.

The sequence of execution in order to use continue statement in different loop structure is given below.

  • • For the for loop, continue causes the conditional test and then the increment portions of the loop to execute.
  • • For the while and do – while loops, program control passes to the conditional tests.
  • • Like a break, continue should be protected by an if statement. You are unlikely to use it very often.

The goto statements

C has a goto statement which permits unstructured jumps to be made. Its use is not recommended. The goto statement requires a label for operation. A label is a valid C identifier followed by a colon. Furthermore, the label must be in the same function as the goto that uses it. The jumps between function are not permitted. The general from of goto statement is

goto label
    .
    .
    .
    Label:

The return statement

The return statement is used to return from a function. It is jump statement because it causes execution to return (jump back) to the point at which the cell to the function was made. If return has a value associated with it, that value is the return value of the function. If no value is specified, assume that a garbage value is returned.

The general form the return statement is
return expression;



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext