GNOME Bugzilla – Bug 614015
Allow multiple values in one case statement inside switch
Last modified: 2017-12-15 14:10:37 UTC
Created attachment 157169 [details] [review] Multivalue 'switch...case' patch This simple patch allows to give multiple values in one case statement. For example, see the following: switch (int_a) { case 0, 1, 2: print ("Here\n"); break; default: print ("Default\n"); break; }
nice Sometime I wish I would have case ranges too: http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Case-Ranges.html#Case-Ranges With your approach that shouldn't be too hard, although generating lot of label is probably a bad idea, it would need a proper switch range support.
(In reply to comment #0) > Created an attachment (id=157169) [details] [review] > Multivalue 'switch...case' patch > > This simple patch allows to give multiple values in one case statement. For > example, see the following: > > switch (int_a) { > case 0, 1, 2: > print ("Here\n"); > break; > default: > print ("Default\n"); > break; > } It's redundant syntax (at least now) - you can write it in a way similar to C/C++/C#/...: switch (int_a) { case 0: case 1: case 2: print ("Here\n"); break; default: print ("Default\n"); break; }
Created attachment 365529 [details] [review] parser: Accept comma-separated list in case-statements of switchs switch (i) { case 0, 1, 2: break; }