SelectCase

Andreas Raab andreas.raab at gmx.de
Thu Jan 5 11:59:08 UTC 2006


Lic. Edgar J. De Cleene wrote:
> I try to avoid using case statements , by I never could found how I could do
> , with a dictionary, a following Pascal equivalent

Simple:

> - case variable of 

map := Dictionary new.

> 0: begin (* executes for 0 value *)
>    end;

map at: 0 put: ["execute for 0"].

> 1, 3: begin * executes for 1 and 3 value *)
>     end;
map atAll: #(1 3) put:["executes for 1 and 3"].

> 4: begin * executes for 4 value *)
>   end;

map at: 4 put: ["execute for 4"].

> 5..9: begin * executes for all values between 5 and 9 *)
>   end;

map atAll: (5 to: 9) put:["executes for all values between 5 and 9"].

>  otherwise (* executes for any different value *)
>  end;

elseBlock := ["executes for any different value"].

> Thanks for this thread and wait HOW TO in Squeak.

^(map at: variable ifAbsent:[elseBlock]) value.

Cheers,
   - Andreas



More information about the Squeak-dev mailing list