Yazoo ---> Online Help Docs ---> Yazoo scripting ---> Loops and if blocks

if

An if clause in Yazoo is written in the following style:


    if villain.name == "Bob"
       print("Bob did it.\n")
    end if       | or endif
   

An if executes the code between itself and its respective end if only if the conditional expression after the if evaluates to true. Notice that the end if can also be written as one word, endif.

In Yazoo, a conditional expression always involves one of the comparison operators `==' (if equal), `/=' (if not equal), `==@' (if aliased at), `/=@' (if not aliased at), `<', `>', `<=', or `>='. In contrast to C, statements like if true or if a = b are not allowed (single `=' is an equate). The last four operators that we wrote take only numeric arguments. On the other hand, `==' and `/=' can compare the contents of any pair of variables or constants which have an identical type. Generally speaking, if a = b is legal, then if a == b... is also valid. So if we have


    a :: { i :: j :: ulong }
    b :: { m :: sshort, n :: double }
    c[2] :: ulong
   

then if a == b is valid because different numeric types can still be compared to each other, but if a == c causes an error since `a' has two width-1 members while c contains a single member spanning two indices.

We can build up compound conditionals by conjoining these simple expressions with `and', `or', `xor' and augmenting them with `not'. The first three take both left- and right-hand conditional arguments (both of which are always evaluated), and return true only if either (or), both (and), or only one but not both (xor) expressions come out true. not only takes a right-hand conditional argument; if that argument is true it returns a false and vice versa. As an example we give:


    if (not a /= b) and ((a < b or a > b) xor a == b)   | assume 'a' and 'b' numeric
   

which is really just a high-handed way of writing "if a == b".


Prev: Loops and if blocks   Next: while and do until


Last update: July 28, 2013

Get Yazoo scripting language at SourceForge.net. Fast, secure and Free Open Source software downloads