The goto statement in c++

The goto statement in c++

The "goto" statement

The" goto" statement is an unconditional control transfer statement. It is used to transfer the control to a specified label in the same program without evaluating any condition.

The syntax of the goto statement is:

goto label;

where

label represents the label in the program to which the control is to be transferred.
Label can be any name followed by a colon. It is given anywhere in the program. Any word that can be used as a variable name can be used as a label in a C++ program.

Program:

Write a program to transfer the control from one statement to another by using the "goto" statement.

#include<iostream.h>
main()
{
cout<< "This program explains the ";
cout<< "use of goto statement" << endl;
goto abc;
cout<< "Programming in C++\n";
cout << "it is an object oriented ";
cout<< "Programming Language";
abc:
cout<< "Program is terminated\n";
cout << "OK";
}
Creative Commons License
Pakistan How by Tahira Aijaz is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.