[Message Deleted]
-
It's from C# language specification: When multiple switch, while, do, for, or foreach statements are nested within each other, a break statement applies only to the innermost statement. To transfer control across multiple nesting levels, a goto statement (§8.9.3) must be used. using System; class Test { static void Main(string[] args) { string[,] table = { {"Red", "Blue", "Green"}, {"Monday", "Wednesday", "Friday"} }; foreach (string str in args) { int row, colm; for (row = 0; row <= 1; ++row) for (colm = 0; colm <= 2; ++colm) if (str == table[row,colm]) goto done; Console.WriteLine("{0} not found", str); continue; done: Console.WriteLine("Found {0} at [{1}][{2}]", str, row, colm); } } }
Ahhhh! Not the notorious goto! X|
Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
Ahhhh! Not the notorious goto! X|
Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
Well, I don't much like goto myself but that's the way Microsoft specifications provide. The good thing is that at least all finally blocks are still processed so not much harm is done. Sometimes goto is far more comprehensive than additional boolean flags and checks in nested loops.
-
Richard Hartness wrote:
ase statements are terminated with the C# keyword break. Unde
I guess you could have a boolean flag as part of the while loop, bool isBreakingFromDefault, and just set that flag to true when you break from default. When the while loop sees that flag as true, break from the while loop as well. FWIW, I think the switch construct is butt ugly and often confusing. I'd much rather see a few if/elses.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
Judah Himango wrote:
FWIW, I think the switch construct is butt ugly and often confusing. I'd much rather see a few if/elses.
Wow - I think the reverse. They are, of course, the same thing in the end.
Christian Graus - C++ MVP
-
-
Ahhhh! Not the notorious goto! X|
Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
It's not notorious when used to branch to the end of a block. In fact, that's what
break
andreturn
do. Djikstra's paper has to do with branching into a control block, there making program verification orders of magnitude more difficult. /raviMy new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com
-
-
Richard Hartness wrote:
ase statements are terminated with the C# keyword break. Unde
I guess you could have a boolean flag as part of the while loop, bool isBreakingFromDefault, and just set that flag to true when you break from default. When the while loop sees that flag as true, break from the while loop as well. FWIW, I think the switch construct is butt ugly and often confusing. I'd much rather see a few if/elses.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango