Classes Lesson

Pages: 123


honestly, you are using it 'properly' as far as syntax and everything is concerned.. but..

if you read up on the goto from BASIC, that command has been shunned since then..

I don't really know this forums policies for posting links to other sites, but you can find more information by searching for goto and C++..

there is some information on this site: http://www.cplusplus.com/doc/tutorial/control/ then CTRL+ F and goto.. he explains more about it

if you do use it, just to get the satisfaction of getting a working program, like I will do sometimes, just know that you should change that as its not suggested.
If you really want an example of how to use goto, look at this:

1
2
3
4
5
6
7
8
for(int i = 0; i < some_value; ++i) {
    for(int j = i; j < some_value+5; ++j) {
        for(std::vector<unsigned int>::iterator k = some_vec.begin(); k != some_vec.end(); ++k) {
            if(j == i && *k > 10 && k < j+i) goto get_me_out_of_here;
        }
    }
}
get_me_out_of_here://... 


In that kind of case I would suggest using goto instead of cluttering your code up with a bunch of if(/*...*/) break;
I thought goto could only go backwards in the code.
goto lets you go wherever you want, even letting you do evil things:

1
2
3
4
5
6
7
8
9
void evil_func() {
evil_goto:
    return; //Uh oh
}

int main() {
    goto evil_goto;
    return 0;
}


I stand corrected.
Last edited on
Last edited on
Topic archived. No new replies allowed.
Pages: 123