Return to Start

Hello, i am new here. I was wondering is there was a way to tell a script to return to the beginning and start everything over again. like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter #\n";
cin>>num;
cin.ignore();
if (num == 1)
{
///////////////////////////////SOMETHING HERE TO MAKE IT RETURN 
///////////////////////////////AND DO EVERYTHING AGAIN.
}
}


thanks for the help guys. :)
They're called loops. Specifically, you want either a while or a do-while loop:

1
2
3
4
5
do
{
  // put code you want to repeat in here
  //  it will repeat as long as some_condition is true
}while( some_condition );


Example:

1
2
3
4
5
6
do
{
  cout<<"Enter #\n";
  cin>>num;
  cin.ignore();
}while(num == 1);


This will keep asking the user for a number until they input a number other than 1
Okay, thank you. :)
Topic archived. No new replies allowed.