11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

or immediately after a $SELECT function. For more details on the naked indicator, seeNaked Global <strong>Reference</strong> in Using <strong>Caché</strong> Multi-Dimensional Storage.ExampleIn this example, the $SELECT function selects the destination for the GOTO based on theuser's input.StartREAD !,"Which level: ",aQUIT:a=""SET x=$SELECT(a=1:"Level1",a=2:"Level2",a=3:"Level3")GOTO @xNotesIncluding a Default ValueTo ensure that a error never results, you should always include the value 1 asthe last expression with an appropriate default value at the end of the list. For example:StartREAD !,"Which level: ",aQUIT:a=""SET x=$SELECT(a=1:"Level1",a=2:"Level2",a=3:"Level3",1:"Start")GOTO @xIf the user enters a value other then 1, 2, 3, or the null string, control is passed back to theprompt.Replacing the IF CommandYou can use $SELECT to replace IF command clauses. The following example uses IF,ELSEIF, and ELSE clauses to determine whether a number is odd or even.OddsREAD !,"ENTER A NUMBER: ",XQUIT:X=""WRITE !,"THE NUMBER IS "IF X#1 { WRITE "NOT AN INTEGER" }ELSEIF X#2=1 { WRITE "ODD" }ELSE { WRITE "EVEN" }GOTO Odds$SELECTThe following example also accepts a number and determines if the number is odd or even.It uses $SELECT to replace the IF command in the previous example:OddsREAD !,"ENTER A NUMBER: ", XQUIT:X=""WRITE !,"NUMBER IS ",$SELECT(X#1:"NOT AN INTEGER",X#2=1:"ODD",1:"EVEN")GOTO Odds<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 297

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!