Difference between revisions of "Talk:Appearance rates"
Jump to navigation
Jump to search
imported>Bale (Created page with 'StDoodle, regarding our recent discussion regarding the switch statement: How's this for a nice use of it to increase code readability? Incidentally, there was a bug in the origi…') |
imported>StDoodle |
||
Line 1: | Line 1: | ||
StDoodle, regarding our recent discussion regarding the switch statement: How's this for a nice use of it to increase code readability? Incidentally, there was a bug in the original code -- it didn't pick out bosses. --[[User:Bale|Bale]] 05:00, 6 May 2010 (UTC) | StDoodle, regarding our recent discussion regarding the switch statement: How's this for a nice use of it to increase code readability? Incidentally, there was a bug in the original code -- it didn't pick out bosses. --[[User:Bale|Bale]] 05:00, 6 May 2010 (UTC) | ||
+ | |||
+ | It still doesn't clarify that one can use completely "unrelated" variables in the individual case statements. Ie, you could do the following (if I'm not mistaken): | ||
+ | {{CodeSample| | ||
+ | code= | ||
+ | <syntaxhighlight> | ||
+ | int a; | ||
+ | //stuff may happen to a | ||
+ | boolean [string] blah; | ||
+ | //blah may get populated | ||
+ | foreach x in blah { | ||
+ | switch { | ||
+ | case x == "hello": | ||
+ | print("kitty"); | ||
+ | break; | ||
+ | case a > 9000: | ||
+ | print("spare me the memes"); | ||
+ | break; | ||
+ | //etc. | ||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight>}} | ||
+ | --[[User:StDoodle|StDoodle (#1059825)]] 15:58, 6 May 2010 (UTC) |
Revision as of 15:58, 6 May 2010
StDoodle, regarding our recent discussion regarding the switch statement: How's this for a nice use of it to increase code readability? Incidentally, there was a bug in the original code -- it didn't pick out bosses. --Bale 05:00, 6 May 2010 (UTC)
It still doesn't clarify that one can use completely "unrelated" variables in the individual case statements. Ie, you could do the following (if I'm not mistaken):
int a;
//stuff may happen to a
boolean [string] blah;
//blah may get populated
foreach x in blah {
switch {
case x == "hello":
print("kitty");
break;
case a > 9000:
print("spare me the memes");
break;
//etc.
}
}
--StDoodle (#1059825) 15:58, 6 May 2010 (UTC)