SWITCH .. CASE .. SWEND Verbs - BBj

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

BBj-Specific Information

In BBj 17.0 and higher, the SWITCH and CASE verbs accept any expression.

Example

input "1..5? ",x
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 "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 "num,str,obj (n,s,o)? ",x$
x$ = cvs(x$,8)
x! = null()
if pos("n"=x$)=1 then x! = 42
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 number 42"; break
    case null(); print "found the object null()"; break
    case default; print "found unexpected value ",x!
swend

See Also

Verbs - Alphabetical Listing