goto statement

Hello Experts,

I am not a programming savvy. I need a help from you guys

can someone help me to understand the negative implications of goto statement. what is bad about it.

any help is greatly appreciated
Google "goto considered harmful".
Here is an example of how it can be used badly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main() {
    int a = 0, b = 0, c = 0;
    cin >> a >> b >> c; //assume error checking etc
start:
    if(a > 6) goto a;
    else if(b < 2) goto b;
    goto 5;
l1:
    goto start;
b:p:
    if(c == 5) goto z;
a:
    if(a < 6 && b > 1) goto aa;
    else goto p;
z:aa:
    goto g;
g:
    cout<<(a+b+c)%5<<endl;
    return 0;
}
Last edited on
I believe labels have to be identifiers.
Can of worms.

Here's some more reading for you.
http://www.cplusplus.com/forum/beginner/2287/


[edit] In C and C++, yes, they have to be identifiers. In Pascal, they can be numbers.
Last edited on
You can also goto pointers (I think that's because in asm, you can jump to addresses (actually, all jumps to identifiers are precomputed to memory addresses IIRC); e.g. jmp 0x1000 (near jump) or jmp 8:0x1000 (far jump)).

Quote from K&R:
Pointers have also been lumped with goto to make impossible to understand programs.
(something like that, anyway).
That's a GCC extension.
Are you talking about this? http://www.cplusplus.com/forum/general/13637/
Yes.
Topic archived. No new replies allowed.