if expressions

An if expression is a control flow construct that allow us to conditionally execute a piece of code depending on the value of a boolean condition. Since it is an expression, it returns the value of the last expression in the branch.

You can combine several conditions using boolean operators like && (and), || (or), etc. You can also add an optional else branch like in many other programming languages.

Example

fn main() {
    let lang = 'Cairo';
    let version = '2.11.4';
    let updated = true;

    if lang == 'Cairo' && version == '2.11.4' {
        assert!(updated);
    } else {
        assert!(!updated)
    }
}

You can experiment with this example in cairovm.codes and read more about if expressions in the Cairo Book.