SWITCH .. CASE .. SWEND Verbs - BBj

For this topic's original documentation, see SWITCH .. CASE .. SWEND Verbs.

BBj-Specific Information

The original implementation of SWITCH..CASE..SWEND in PRO/5, and before BBj 17.00, is limited to integer expressions. In BBj 17.00 and higher, the SWITCH and CASE verbs accept any value, including strings, objects, and non-integer numbers.

Example

input (0,err=*same)"Integer (1..5): ",x:(9)
a = 1
switch x
    case a; print "one"; break
    case 2; print "two"; break
    case 3; print "three"; break
    case 4; print "four"; break
    case 5; print "five"; break
    case default; print "other"; break
swend

input "Letter (a..e): ",x$
c$ = "c"
switch x$
    case "a"; print "a"; break
    case "b"; print "b"; break
    case c$; print "c"; break
    case "d"; print "d"; break
    case "e"; print "e"; break
    case default; print "other"; break
swend

input "Choose i=integer,n=number,s=string,o=object,other=null() ",x$
x$ = cvs(x$,8)
x! = null()
if pos("i"=x$)=1 then x! = 42
if pos("n"=x$)=1 then x! = Math.PI
if pos("s"=x$)=1 then x! = "xyzzy"
if pos("o"=x$)=1 then x! = bbjapi()
print "switch ",x!
switch x!
    case bbjapi(); print "found the object bbjapi()"; break
    case "xyzzy"; print "found the string xyzzy"; break
    case 42; print "found the integer 42"; break
    case null(); print "found the object null()"; break
    case default; print "found ",x!
swend

See Also

Verbs - Alphabetical Listing