cancel
Showing results for 
Search instead for 
Did you mean: 

If conditions $ vs ?

Denakaran
New Contributor II

Sometimes i wonder how the $ differs with ? since most of the times both of them  returning the same results. Not sure when to use $ and ?.  Help me to understand this guys!


q)$[1b;`true;`false]
`true
q)?[1b;`true;`false]
`true
q)t:([]name:enlist `hi)
q)t
name
----
hi
q)$[(count t)>0;`values;`novalues]
`values
q)?[(count t)>0;`values;`novalues]
`values

1 ACCEPTED SOLUTION

BaiChen
New Contributor

? can be used in vector-based condition . For example:

?[101b;`a;`b]
`a`b`a
q))

$ is used in single condition :
$[1b;`a;`b]
`a
q))

 




View solution in original post

3 REPLIES 3

BaiChen
New Contributor

? can be used in vector-based condition . For example:

?[101b;`a;`b]
`a`b`a
q))

$ is used in single condition :
$[1b;`a;`b]
`a
q))

 




Denakaran
New Contributor II

 

Thanks, that helps! 

sujoy13
New Contributor II

Apart from vector-based condition mentioned above, ? Will always run the fail condition unlike $.

$[1;2;’err]

?[1;2;’err]