Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

goto considered harmless

Name: Anonymous 2018-05-10 11:02

I was reading Bjarne Stroustrup's sepples book and found this

One of the few sensible uses of goto in ordinary code is to break out from a nested loop or
switch-statement (a break breaks out of only the innermost enclosing loop or switch-statement).
For example:


void f()
{
int i;
int j;
for (i = 0 ; i <n ; i ++)
for (j = 0 ; j <m ; j ++) i f (nm [i][j ] == a ) goto found ;
// not found
// ...
found :
// nm[i][j] == a
}

Name: Anonymous 2018-05-10 11:07

>>1
The original "Goto considered harmful" complaint was about spaghetti code that consisted of gotos. Purists extrapolated this to mean that goto is some ancient hack that should be avoided at all costs somewhere in the late 90's.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List