0

I'm stuck with goto. I need to stop cause sometimes, it screws up my code. I used to do something like this.

int command;
start:
command = NULL; // this was a random guess to see if it would work
cin >> command;
if(command == 1){
cout << "Your chose 1" << endl;
pause; //I defined this
goto start;
}

And so after some heated debates over goto, I decided to try out the while. So now my code looks like this.

int command;
cin >> command;
        while(command == 1) 
               { 
                      reset; //resets command to null (this is defined)
     cout << "You chose 1" << endl;
               pause; //defined
  }

But when I run that, the code works other than the fact that it exits out after pause. How do I have it go back to the main "cin"?

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by firstPerson
1

lines 5 and 7 are do-nothing lines. The don't do a damned thing. You could delete both lines and the loop would work the same way.

>>//resets command to null
Says who???

Edited by Ancient Dragon: n/a

0

Think about the flow.

How was the goto working?

Does the while loop take the flow the same way?

You need the flow to reach back to the cin.

For that you need to include the cin also in the loop.

Edited by thomas_naveen: n/a

1

>> But when I run that, the code works other than the fact that it exits out after pause. How do I have it go back to the main "cin"

int cmd = 0;
while( cin >> cmd) {
  if(cmdIsBad()) break; //out of the loop
  /* else logic goes here */
}

Edited by firstPerson: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.