If, If..Else, If..ElseIf..Else

Unlike the control structures introduced above, the next three are not concerned with the Time variable, but allow the user to specify conditional execution by providing Boolean expressions. They do not require much explanation really so all that is included here is the syntax:

    If <expr>:
        <body>
        ...

    If <expr>
        <body1>
        ...
    Else
        <body2>
        ...

    If <expr1>
        <body1>
        ...
    ElseIf <expr2>
        <body2>
        ...
    ElseIf <expr3>
        <body3>
        ...
    .
    .
    Else
        <default_body>
        ...

Note that the block terminating symbol ... must appear after the end of every <body> section. Also note that conditional expressions do not need to be surrounded by brackets as they do in C and C++.


©1999,2000 Mark Pearson m.pearson@ukonline.co.uk April 30, 2000