Posted By:
2 Jul, 2013 6:43 am PDT

goto statement in C++

What is goto statement? What is the use of it?
Attachment:None


goto allows absolute jump to another point in the program. The use of goto should be limited because the execution of goto can cause unconditional jump ignoring any type of nesting limitations.

The destination point is identified by a label which is then used as an argument for goto statement.

Eg:

// Program to print from 5 down to 1 using goto

#include<iostream.h>

#include<conio.h>

int main()

{

int n;

n=5;

loop:

cout<<n<<"  ";

n--;

if(n>0)

goto loop;

cout<<"\nEnd of goto";

getch();

}

 

Output of the program is:

5  4  3  2  1

End of goto

 

In line 10 the goto keyword is encountered, so the execution of the program now continues from line 6.

 

Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud