C++ Program to Read a Valid Number (goto statement)

In this program, the user is ask for integer number, if he/she enters 0 (ZERO) then it will again ask for the number until he enters a valid number.

Here we have used goto statement.

A goto statement in C programming provides an unconditional jump from the 'goto' to a labeled statement in the same function. Any program that uses a goto can be rewritten to avoid them.

Syntax:    goto label;

Example:    goto start;



Source Code
#include <iostream>
using namespace std;

int main ()
{
    int no;
accept:
    cout<<"Enter any Number: ";
    cin >> no;
    if (no == 0)
        goto accept;
    cout<<"You have entered " << no;
    return 0;
}
Output
Enter any Number: 0
Enter any Number: 0
Enter any Number: 12
You have entered 12