|Home | Tutorial | Classes | Functions | QSA Workbench | Language | Qt API | QSA Articles | Qt Script for Applications |

[Prev: for] [Home] [Next: finally]

### if

    if ( expression1 ) {
        // statements1
    else {
        // elsestatements
    }

    if ( expression1 ) {
        // statements1
    else if ( expression2 ) {
        // statements2
    }
    // else if ...
    else {
        // elsestatementsN
    }

An `if` statement provides a two-way branch. A multi-way branch is achieved using `else if`s. (See also switch.)

1. If the first expression, expression1, is `true`, then the statements governed by that expression (statements1) will be executed, after which control will pass to the statement following the `if` block.

2. If expression1 is `false`, control passes to the `else` statement. If the `else` has no following `if`, the `else` statements (elsestatements) are executed, after which control will pass to the statement following the `if` block. If the `else` has a following `if`, then step 1 or step 2 (this step) is repeated for that `if` statement depending on whether its expression is `true` or `false`.

[Prev: for] [Home] [Next: finally]