switch case question

Kay C Lan lan.kc.macmail at gmail.com
Tue Oct 31 05:22:46 EST 2006

On 10/22/06, Martin Baxter <mb.userev at harbourhosting.co.uk> wrote:

> put gtimedtest is empty into isempty
> switch isempty
>   case true
>    stuff
>    break
>   case false
>    other stuff
>    break
> end switch

I've come into this a little late, no internet for a week or so, but
be aware that switch is slower than if-then-else-end if, no matter who
many nested ifs are required to do 'the same' as a mult-case switch
statement. It's only a couple of milliseconds over 1000 executions,
but it is slower.

If what you want is as stated, then I think you'd be better served by:

if (gTimeTest is empty) then
  --do empty stuff
  --do full stuff
end if

Having said that, I've started to use switch a lot because what
appears at first glance to be a simple yes/no,true/false,black/white,
after a week of tweaking I realise that yes/no/maybe,true/false/no
comment, and black/white and all the other colours of the rainbow also
need to be considered: and this is where switch is so easy to read and

Here is another version for your switch command:

 case (gTimeTest is empty)
   --do empty stuff
   -- do full stuff
end switch

Which then makes it easy when you decide to do things based on the
exact contents of gTimeTest

 case (gTimeTest = "1:00")
    revSpeak "It's one o clock"
 case (gTimeTest = "2:00")
    revSpeak "It's too o clock"
 case (gTimeTest contains ":30")
 case (gTimeTest is not empty)
    --do whatever
    answer "There is an error, gTimeTest is empty"
end switch

More information about the Use-livecode mailing list