Priniting Given Word using Goto Statement in C++


  • It initializes a variable i to 1.
  • It prompts the user to enter a limit.
  • It reads the limit into the variable n.
  • It uses a goto statement to create a loop that prints the word "Goto" and increments the value of i.
  • It checks if i is less than or equal to n. If it is, the loop goes back to the start label and repeats. If it is not, the loop exits.
  • The program ends.

While this program works correctly, using a goto statement is generally not considered good programming practice because it can make the code difficult to read and maintain. A better alternative would be to use a for or while loop to print the word "Goto" a given number of times.

Source Code

#include<iostream>
using namespace std;
int main()
{
    int i=1,n;
    cout<<"\nEnter The Limit:";
    cin>>n;
    start:
            cout<<"\nGoto";
    i++;
    if(i<=n)
    {
        goto start;
    }
    return 0;
}
To download raw file Click Here

Output

Enter The Limit:5
Goto
Goto
Goto
Goto
Goto

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples