Booleans and Conditionals
#
BooleansThe type of a boolean value is bool
. Here is how to define a boolean
value:
Common operations:
#
Comparing ValuesIn LIGO, only values of the same type can be compared. Moreover, not
all values of the same type can be compared, only those with
comparable types, which is a concept lifted from
Michelson. Comparable types include, for instance, int
, nat
,
string
, tez
, timestamp
, address
, etc. As an example of
non-comparable types: maps, sets or lists are not comparable: if you
wish to compare them, you will have to write your own comparison
function.
#
Comparing Strings#
Comparing numbers#
Comparing tez๐ก Comparing
tez
values is especially useful when dealing with an amount sent in a transaction.
#
ConditionalsConditional logic enables forking the control flow depending on the state.
You can run the compare
function defined above using the LIGO compiler
like this:
When the branches of the conditional are not a single expression, as above, we need a block:
As an exception to the rule, the blocks in a conditional branch do not
need to be introduced by the keyword block
, so we could have written
instead: