Switsch Statement like in java.

Dirk Wessels icircle at xs4all.nl
Wed Sep 7 14:17:11 UTC 2005


----- Original Message -----
> If you find any natural example where cond:cond:cond:... where it would
> be advantageous to use it, I would be grateful if you let me know. Until
> know I have none.
The only place I would use case structures in, would be in
not-object-oriented finite-state-machines,
and in handling some types of input.

I know the pascal case variant, that only works with ordinal types (integer
etc)..

procedure Test(key:Char);
begin
  case key of
    '0'..'9': writeLn(You typed a number');
    'a'..'z','A'..'Z': writeLn('You typed a alphabetic character');
    '+','-','*','/': writeLn('You typed a math -symbol')
    else writeLn('You typed something else');
  end;
end;
The compiler usually implements this as a jump-table..

In smalltalk one would use a Dictionary instead.
A dictionary is more flexible, because one can add and remove associations.





More information about the Squeak-dev mailing list