Case Range Statement ..

Adam D. Ruppe destructionator at gmail.com
Tue Jul 7 10:10:25 PDT 2009


On Wed, Jul 08, 2009 at 02:48:31AM +1000, Derek Parnell wrote:
>    switch (X) {
>       case 1: funcA(); break;
>       case 2,5,7,10 .. 17, 24, 32: funcB(); break;
>       case 3,6,8,18 .. 23: funcC(); break;
>    }
> In other words, allowing a range of value inside a list of values.
> 
> How is this possible in today's D?

switch(X) {
	case 1: stuff; break;
	case 2,5,7: case 10: .. case 17: case 24,32: stuff; break;
	case 3,6,8: case 18: .. case 23: stuff; break;
}

This compiles on the new dmd. Only one item is allowed on a case range,
but you can just use fall through behaviour to make it its own case right
after the list.




-- 
Adam D. Ruppe
http://arsdnet.net



More information about the Digitalmars-d mailing list