goto previous goto statement

what i'm trying to do is:

1: /*code*/
2: goto a1; /*goto 1*/
3: /*code*/
4: goto a1; /*goto 2*/
5: /*code*/
6: a1:
7: /*code*/
8: /*mystery command*/

the order of the lines read is:
1->2->6->7->8->3->4->6->7->8->5->6->7->8->5.......

i want to know what to put in for " /*mystery command*/ " (line 8)

in words, line 8 will goto the last "goto" statement the code processed

i'm sorry if this is kinda confusing, it's the only way i can describe it without explaining it in person.
Last edited on
Sounds like you want a function.

Btw, goto's are considered really bad practice considering you have functions and loops in C++.
the order of the lines read is:
1->2->6->7->8->3->4->6->7->8->5->6->7->8->5.......

Oh, you must be kidding me... Do not use goto.
Here are some links that will help you in doing the transition from assembler to C++:
http://www.cplusplus.com/doc/tutorial/control/
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
The ONLY reason goto is even supported in C++ is because a handfull of people used them in C, and in order to maintain compatibility with the hundreds of all ready written libraries the designers of C++ decided to allow it.

Just in writting that first sentence I thought of five different ways of doing what it is you are trying to describe (yes everyone here understands you btw). Functions are the way for you to go, I think you'll like them alot based on the way you wrote that since they return at the end of their execution so mistakes like the one you made with not jumping to Line 3 won't matter.

Just curious are you coming off of Assem, Bat or Batch?
i know about loops, i use them all the time, but loops require something to happen 1st. sometimes i want something like:
if(....){goto ....;}

which will take you out of the if statement. i want something that will calculate something, and then go back to what it was doing before it calculated it
sometimes i want something like: if(....){goto ....;}

The feature you are looking for is called "functions". See here for an introduction:
http://www.cplusplus.com/doc/tutorial/functions/
+1 Athar

@ OP: You are describing functions exactly.
Topic archived. No new replies allowed.