Tharwat 发表于 2022-7-5 19:13:33

No, if the variable s is not equal to either "Y" "y" "N" "n" the t symbol at the end would give you an option to set the variable ( for example ) to any value you want or print a message to user etc...

samifox 发表于 2022-7-5 19:15:01

So its a defualt action in case none of the expression is true? So its could be (t (prints "illegel value"). So t is just a trigger in endcof the cond?

Tharwat 发表于 2022-7-5 19:19:15

Close , have a look .
 

(cond((= s "Y") 1)   ((= s "y") 1)   ((= s "N") 0)   ((= s "n") 0)   (t (alert "Variable (s) in not equal to any of the above check outs ")))

samifox 发表于 2022-7-5 19:25:04

Its not what i meant?

Lee Mac 发表于 2022-7-5 19:27:02

Put simply, a test expression of 't' will always be validated and so this represents a default condition for when all other conditions are not met; such a condition is by no means necessary, but usually provided by the documentation to help explain how to include a default condition.
 
It looks like you understand this.

hugha 发表于 2022-7-5 19:31:02

The equivalent in another syntax style could be
 
 
if (s=="Y")
    return 1
elseif (s=="y")
    return 1
elseif (s=="N")
    return 0
elseif (s=="n")
    return 0
else
    alert( "Variable (s) in not equal to any of the above check outs ")
endif
 
 
Think of (t ....) as being an all-inclusive "else" or "otherwise".
页: 1 [2]
查看完整版本: cond() - why ((t nill)) is com