Use of goto keyword

As we studied in C keywords chapter,  goto is a C keyword which is used to take the control where you want.

We learn use of goto keyword in below C program.

#include<stdio.h>
int main()
{

int count = 0;

while (count <= 10)
{

if (count == 5)

{

goto here;

}
printf(“%d \t”,count);
count++;

}

if (count == 5)
{

printf(“Count = %d\n”,count);

}
else
{

printf(“Count is not equal to 5\n”);

}

here:
printf(“Escape if – else expression\n”);

return 0;

}

Explanation :-
My intesion is to escape  if – else statement when value of count becomes equal to 5 in above C program, so using goto keyword you can take control where you want, the output is :-
$  ./a.out
0    1    2    3    4    Escape if – else expression

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.