> case foo of
>   0..3: blarg(1);
>   4, 11: blarg(2);
>   5: blarg(3);
>   6-8: blarg(4);
>   9: blarg(5);
>   10: blarg(6);
> end;
> 
> ...can be compiled as:
> 
>    if foo >= 6 then goto 9;
> 0:
>    if foo > 3 then goto 4;
>    blarg(1);
> 4:
>    if foo = 5 then goto 5;
>    blarg(2);
>    goto end;
> 5:
>    blarg(3);
>    goto end;
> 6:
>    blarg(4);
>    goto end;
> 9:
>    if foo < 9 then goto 6;
>    if foo >= 10 then goto 10;
>    blarg(5);
>    goto end;
> 10:
>    if blarg = 11 then goto 4;
>    blarg(6);
> end:

otherwise written as... Note this removes some unnecessary tests...

if foo >= 6 then begin
  if foo < 9 then Blarg(4)
  else if foo >= 10 then begin
    if foo = 11 then Blarg(2)
    else Blarg(6);
  end
  else Blarg(5);
end
else if foo > 3 then begin
   if foo = 5 then Blarg(3)
   else Blarg(2);
end
else Blarg(2);

better would be

const Blargs :array[0..11] of integer = (1,1,1,1,2,3,4,4,4,5,6,2);
begin
   Blarg(Blargs[Foo]);
end;

or some other hashing function to shorten the tests... A compiler could
be designed to choose the best method available based on conditions... A
compiler conditional could even be added to indicate Space vs Speed preferences.

Allowing generic use of control statements like case enables cone to take advantage
of future compiler performance improvements without changing code... It would be nice
to see the ordinals only restriction removed from 'case' and implemented by the
compiler as cascaded 'if else if' chains where necessary...

--
Aaron Scott-Boddendijk
Jump Productions
(07) 838-3371 Voice
(07) 838-3372 Fax


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to