[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CGoto
You can only jump to the same code block you jump from:
Using goto is considered bad programming practice [?], the use of for and ?while is more appreciated. The active use of goto results in code that is called ?spaghetti code.
You could use goto when you want to end multiple loops, as the break command only breaks one loop.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CGoto
(C) goto
keyword enabling you to make jumps in your code.You can only jump to the same code block you jump from:
void func1(void)
{
goto labelFunc2; //Error: Undefined label 'labelFunc2'
}
void func2(void)
{
labelFunc2:
}
Using goto is considered bad programming practice [?], the use of for and ?while is more appreciated. The active use of goto results in code that is called ?spaghetti code.
You could use goto when you want to end multiple loops, as the break command only breaks one loop.
int myFunction() { return rand()%1000; } int main() { int x = 0; int y = 0; int z = 0; int maxy = 1000; int maxx = 1000; int maxz = 1000; for (z=0; z<maxz; z++) { for (y=0; y<maxy; y++) { for (x=0; x<maxx; x++) { if (myFunction()==0) goto afterloop; } } } afterloop: return 0; }
- include <stdlib.h>
Code links
'goto' links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
