|
-
June 17th, 2011, 03:52 PM
#1
Switch statements limited to constants in case clauses?
On the face of it, it would be handy to be able to list a set of cases which are based on variables rather than consts. This would avoid long if-else statements and clean up some code.
However, as I understand it, switch statements are “sets” not “lists” meaning the order in which case statements are evaluated is not certain. Therefore variable based case clauses would not be safe.
Switch statements do support ranges though. E.g. “case 1..4:”. I am not sure if the compiler would object to case ranges overlapping as this would potentially lead to the situation with variable cases i.e. uncertain order of execution.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|