Josh @ Dreamland
|
|
Posted on: September 08, 2012, 04:47:37 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { if (target[i][j]) break; // FUCK! } } Named Loops:
HOLYFUCKIDONTKNOWWHATTONAMETHISLOOP: for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { if (target[i][j]) break HOLYFUCKIDONTKNOWWHATTONAMETHISLOOP; // yay? } } Numbered breaks:
for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { if (target[i][j]) break 2; // (Y) } }
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #2 Posted on: September 10, 2012, 11:35:23 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
While "both" was originally a joke, I actually think I might do it. My main aversion to it was that it would make goto labels ambiguous, but in the end, (1) do we really want goto, and (2) why can't a loop name also be a label?
It would be simple to just warn on [snip]break 1;[/snip]. Did I mention I'm adding warnings?
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
polygone
|
|
Reply #3 Posted on: September 10, 2012, 11:43:28 pm |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
Having thought about it I now vote break << 1; break << 2; to break one loop back, two loops back.
I think adding both is over-kill and might be confusing, in fact named loops makes things more confusing by itself in that it will make it harder to read other people's code whereas numbered breaks can be universally understood.
|
|
« Last Edit: September 10, 2012, 11:47:55 pm by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
Josh @ Dreamland
|
|
Reply #4 Posted on: September 11, 2012, 07:51:59 am |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
That's pretty ugly, and it doesn't match other languages, so newcomers couldn't really guess it. If we're going to have them learn something new, it should be that the number after break is the total number of loops to exit, not the additional number.
People are really used to named loops, too. We'll let the userbase decide.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #6 Posted on: September 11, 2012, 02:13:23 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
That is what [snip=edl]continue loop;[/snip] would do. Same as [snip=edl]continue 2;[/snip].
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #9 Posted on: September 12, 2012, 05:20:44 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
It is the same as break, so why use it?
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #11 Posted on: September 13, 2012, 01:41:05 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
I'd warn/error on break 0, too.
It's easier to to read break 2, in my opinion; even if you're in a huge nested loop, you have an idea of how many loops you're in, whereas you can easily forget what a loop is named. Granted, you can assume it breaks the big one or huge one based on context, but with break 3, you know it's breaking all of them.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #13 Posted on: September 13, 2012, 02:18:07 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
I see both sides. I'm pretty sure I'll end up doing both; the mechanism that handles the double break will be the same, so the difference between the two implementations C++-side will be in identifying the loop to which the user is referring.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
The 11th plague of Egypt
|
|
Reply #14 Posted on: September 26, 2012, 12:02:23 pm |
|
|
Joined: Dec 2009
Posts: 274
|
If you have to do it, use named loops. It looks like a good companion to goto+label, I think it's a nice fit for a pasta lover.
|
|
|
Logged
|
|
|
|
|