-->

Facebook

Jasper Roberts - Blog

Thursday, March 12, 2015

go to statement in c programming language.

- In c programming language, if statement, if...else statement, switch statements provides conditional jumps.
- A goto statement in C programming language provides an unconditional jump from the goto to a labeled statement in the same function.
- Use of goto statement is highly discouraged in c programming language.
- Because it makes difficult to trace the control flow of a program making the program hard to understand and debug.

- Syntax:
goto label;
.
.
.
label: statement;

-Example:

#include<stdio.h>
#include<conio.h>

void main()
{

  int number = 10;

  A:
       do
       {
          if( number == 15)
      {
         number = number + 1;
         goto A;
      }
      printf("\n value of number is: %d",number);
      number++;
   
   }while( number < 20 );

   getch();
}

OUTPUT:
value of number is:11
value of number is:12
value of number is:13
value of number is:14
value of number is:15
value of number is:16
value of number is:17
value of number is:18
value of number is:19

No comments:

Post a Comment