0
1.8kviews
What is significance of goto, continue and break statement
1 Answer
0
26views

The goto Statement

C supports the goto statement to branch unconditionally from one point of the program to another. The goto requires a label in order to identify the place where the branch is to be made. A label is any valid variable name and must be followed by a colon.

The general from is

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

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


#include <stdio.h>
int main () {
int a = 10;
LOOP:do {
 if( a == 15) {
     a = a + 1;
     goto LOOP;
  }
printf("value of a: %d\n", a);
  a++;
}while( a < 20 );

return 0;
}

The break statement

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

#include <stdio.h>
int main () 
{
     int a = 10;
      while( a < 20 ) {
         printf("value of a: %d\n", a);
         a++;
         if( a > 15) {
           break;
         }
      }
    return 0;
}

The 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.

#include <stdio.h>
int main () {
int a = 10;
do {

  if( a == 15) {
     a = a + 1;
     continue;
  }

  printf("value of a: %d\n", a);
  a++;

  } while( a < 20 );

 return 0;
 }
Please log in to add an answer.