Statements

Expression Statements

An expression followed by a semicolon.

a = b + c;

Variable Declarations

As shown in the Variables section.

let x: uint256 = 5;

Control Flow Statements

If Statements

if (condition) {
    // Statements
} else {
    // Statements
}

Example:

if (balance > 0) {
    // Do something
} else {
    // Do something else
}

While Loops

while (condition) {
    // Statements
}

Example:

let i: uint256 = 0;
while (i < 10) {
    // Do something
    i = i + 1;
}

For Loops

for (initializer; condition; update) {
    // Statements
}

Example:

for (let i: uint256 = 0; i < 10; i = i + 1) {
    // Do something
}

Last updated