Article
· Jun 11, 2016 2m read

NewBie's Corner Session 7 True and False

NewBie's Corner Session 7 True and False

Welcome to NewBie's Corner, a weekly or biweekly post covering basic Caché Material.

Click on the Caché Cube in your system tray and select Terminal to try out these commands.

In COS, a 0 is false and any other number (positive or negative) is true.

Set X=1
If X Write "True"          ;  1 is true and 0 is false
True
 
Set X=0
If X Write "True"          ;  0 is false
<> 
 
Set X=10
If X Write "True"          ; Any number other than 0 is true
True

 

Set X=-10
If X Write "True"          ; Any number other than 0 is true, even negative ones
True
 
Set X="1"
If X Write "True"          ; 1 is true even in alphanumeric text       
True
 
Set X="0"
If X Write "True"          ; 0 is false in alphanumeric text
<> 

 

Set X="01"
If X Write "True"          ; Some of these are tricky
True
 
Set X="1ABC"
If X Write "True"          ; The 1 is used and the rest of the text is ignored
True
 
Set X="0ABC"
If X Write "True"          ; The first numeric is used and the rest of the text is ignored
<>    
                   
Set X="ABC1"               ; If the numeric is not the first character,
If X Write "True"          ; the whole string is ignored
<> 

True and False with alphanumeric text

  • When alphanumeric text (quoted string) contains only a numeric it is evaluated as pure numeric
  • When alphanumeric text (quoted string) has as its first characters a numeric, the numeric is used as a pure numeric, and the rest of the alphanumeric text is ignored
  • When alphanumeric text (quoted string) has as it first characters an alpha character, the whole string is evaluated as 0 or false

I suggest you spend some time on the Terminal trying some of these combinations. They are not always as obvious as you think.

--Mike Kadow

PaulMikeKadow@gmail.com

If you have a comment, please respond through the InterSystems Developer Community, don't send me private email. Unless of course you wish to address me only.

See NewBie Index for an index of all NewBie Corner posts.

 

Discussion (0)0
Log in or sign up to continue