check conditions one by one and execute corresponding block accordingly
Parameters
when conditions :block
Attributes
any
check all conditions, without breaking, regardless of success
has
:any
prepend given value to each of the conditions
Returns
:logical
Examples
copy
; the main block is always evaluated!
when [
prime? 4 -> print "yes, 4 is prime - wait, what?!"
prime? 5 -> print "yes, 5 is prime
prime? 7 -> print "yes, 6 is prime
true -> print "none of the above was true"
]
; yes, 5 is prime
copy
when.any [
prime? 4 -> print "yes, 4 is prime - wait, what?!"
prime? 5 -> print "yes, 5 is prime"
prime? 7 -> print "yes, 7 is prime"
]
; yes, 5 is prime
; yes, 7 is prime
copy
x: 2
when.has: x [
[=0] -> print "x is zero!"
[<1] -> print "x is less than 1"
[<4] -> print "x is less than 4"
true -> print "x is >= 4"
]
; x is less than 4