Discussion: Porting 58000 lines of D and C++ to jai, Part 0: Why and How

FeepingCreature feepingcreature at gmail.com
Thu Nov 24 12:04:27 UTC 2022


On Thursday, 24 November 2022 at 11:37:57 UTC, Hipreme wrote:
> - Agreed, if you can put `case` with static foreach, you should 
> be able to put `else if`
>

This is not a case of "if doesn't work with this normal feature", 
it's a case of "case is extremely, **extremely** strange." Case 
statements work much more like goto labels than statements. For 
instance, this is valid code:

     import std.stdio;
     void switchtest(int i, bool b)
     {
         switch (i)
         {
             case 1:
                 if (b)
                 {
                     case 2:
                         writefln!"Case 1b or 2: %s, %s"(i, b);
                         return;
                 }
                 break;
             default: break;
         }
         assert(false);
     }

     void main()
     {
         switchtest(1, true);
         switchtest(2, false);
     }



More information about the Digitalmars-d mailing list