C Jump Statements

Advertisements

Jump Statements in C

Jump statements are used to interrupt the normal flow of program.

Types of Jump Statements

  • Break
  • Continue
  • GoTo

Break Statement

The break statement is used inside loop or switch statement. When compiler finds the break statement inside a loop, compiler will abort the loop and continue to execute statements followed by loop.

Example of break statement


	#include<stdio.h>

       void main()
       {
              int a=1;

              while(a<=10)
               {
                   if(a==5)
                     break;

                    printf("\nStatement %d.",a);
                   a++;
                }
                    printf("\nEnd of Program.");
       }

   Output :

              Statement 1.
              Statement 2.
              Statement 3.
              Statement 4.
              End of Program.

Continue Statement

The continue statement is also used inside loop. When compiler finds the break statement inside a loop, compiler will skip all the followling statements in the loop and resume the loop.

Example of continue statement


	#include<stdio.h>

       void main()
       {
              int a=0;

              while(a<10)
               {

                   a++;

                   if(a==5)
                     continue;

                    printf("\nStatement %d.",a);

                }
                    printf("\nEnd of Program.");
       }

   Output :

              Statement 1.
              Statement 2.
              Statemnet 3.
              Statement 4.
              Statement 6.
              Statement 7.
              Statement 8.
              Statement 9.
              Statement 10.
              End of Program.

Goto Statement

The goto statement is a jump statement which jumps from one point to another point within a function.

Syntax of goto statement


              goto label;
                    - - - - - - - - - -
                    - - - - - - - - - -
              label:
                    - - - - - - - - - -
                    - - - - - - - - - -
			

In the above syntax, label is an identifier. When, the control of program reaches to goto statement, the control of the program will jump to the label: and executes the code after it.

Example of goto statement


	#include<stdio.h>

       void main()
       {
                    printf("\nStatement 1.");
                    printf("\nStatement 2.");
                    printf("\nStatement 3.");

                    goto last;

                    printf("\nStatement 4.");
                    printf("\nStatement 5.");

                    last:

                    printf("\nEnd of Program.");
       }

   Output :

              Statement 1.
              Statement 2.
              Statement 3.
              End of Program.

Related topics

Advertisement