Go to Statement

Default Image

To clear the concept of control transfer
we use goto statement. However, it is not a good practice to use goto
statement because it creates ambiguity to understand the flow of
programme. It is unconditional control transfer statement. It transfers
the execution control to a specific label in the same programme. The
general syntax of goto statement is as follows:

goto label;


In this syntax, the “label” represents a
valid C++ user-defined identifier followed by a colon (:) to which a
control is to be transferred. Let’s see an example:


#include

#include

void main()

{

clrscr();

int a=1;

begin:

cout<<“Hello World”<
a++;

if(a<=5) goto begin;

getch();

}


output of the goto programme

You can download goto Statement source code from here

Read Count: 3 times

Comments

No comments yet.

Leave a Comment