Page 1 of 1

Doing an ELSE CASE within a CASE

Posted: Wed Jul 21, 2004 4:42 pm
by datastage
In UV BASIC the case syntax is:

BEGIN CASE
CASE expression
statements
[CASE expression
statements
.
.
.
]
END CASE



In a psuedocode sense I want to have an ELSE after my CASE's and before the END CASE.

What is the best way to approach this. At the moment I'm working on a routine and want to pass an error message to Ans I fail to get a match on my case comparisons. I thought maybe I could set Ans to my error message before my CASE, but there are other places afterwards I want to have error handling, so I'd still need a way to know I didn't have a case match and to exit the routine there with my error message.

Probably easy, but it's been a long day.

Thanks,

Posted: Wed Jul 21, 2004 4:48 pm
by chulett
Don't you just simply setup an @TRUE case at the end as a catch all? Whatever falls into it is the 'else' you are looking for, I believe.

Posted: Wed Jul 21, 2004 6:17 pm
by kduke
Craig is correct.

Code: Select all

begin case
  case x=1
    stmt1
  case y=1
    more stmt
  case @true
    stmt3
end case

Posted: Fri Jul 23, 2004 4:12 am
by ray.wurlod
I once knew a programmer who did this.

Code: Select all

Equate OTHERWISE Lit "CASE 1"

BEGIN CASE
   CASE expr1
      statements
   CASE expr2
      statements
         :
   OTHERWISE
      statements
END CASE
Unfortunately the formatter doesn't know about it, so formats the OTHERWISE line incorrectly, which was subsequently adjusted manually.

Posted: Fri Jul 23, 2004 8:27 am
by kduke
Ray

I used to do this:

Code: Select all

Otherwise = @true

Begin case
  case x=1
  case x=2
  case Otherwise
end case
Reads nice.