no case for CASE
Irv Mullins wrote:
>Here's an example clipped from a progam I wrote some time ago:
>Purpose: to handle user input to a menu:
>
>--Pascal version:
> case key of esc : fini := true;
> 'P' : dec(indx);
> 'N',^M : inc(indx);
> 'F' : indx := 0;
> 'E' : if editmode then SO_DATA.MENU;
> end; {case key}
>
>--Euphoria version (translated)
> if compare(key,esc) = 0 then fini = TRUE
> elsif compare(key,'P') = 0 then indx = indx - 1
> elsif compare(key,'N') = 0 then indx = indx + 1
> elsif compare(key,ctlM ) = 0 then indx = indx + 1
> elsif compare(key,'F') = 0 then indx = 0
> elsif compare(key,'E') = 0 then
> if editmode then SO_DATA_MENU end if
> end if
>--
>
>Anyone want to guess which is
>(1) easier to understand
>(2) less typing
>(3) less likely to have "unexpected consequences" (bugs)?
Irv, are you prepared to be a bit fairer, and leave out the
unnecessary, counter-intuitive compare tests:
if key = esc then fini = TRUE
elsif key = 'P' then indx = indx - 1
elsif key = 'N' or key = ctlM then indx = indx + 1
elsif key = 'F' then indx = 0
elsif key = 'E' then
if editmode then SO_DATA_MENU end if
end if
Slightly more typing, yes, but you may even change your mind about
the rest. Jiri
|
Not Categorized, Please Help
|
|