c# - Breaking out of a 'for' loop from a ''case" statement -



c# - Breaking out of a 'for' loop from a ''case" statement -

this question has reply here:

break out of while loop contains switch statement 14 answers

i asked maintenance work on c# code which, i'm told, converted visual basic 6. (i mention because don't know vb6 don't know if have made more sense in language. . .)

it's got for loop parses text proprietary scripting language using switch within for loop . . .

for ( t = 0; t < upperbound(tokens); t++) { string mystring = tokens[t]; switch (mystring) { case "goto": if (firstgoto == -1) { firstgoto = t; } else { // compute number of tokens in goto pointlength = t - firstgoto - 1; break; // exit } break; case "actuate" . . .

notice comment

// exit

the programmer expects break exit for loop think exit switch statement because documentation break says

the break statement terminates closest enclosing loop or switch statement in appears. command passed statement follows terminated statement, if any.

so right exit switch, still in for, , if so, right way original programmer intended?

yes, break break out of closest loop or switch. easiest way utilize goto. (no, goto not evil)

for { switch(...) { .... goto mylabel; } } mylabel:

c#

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -