Skip to content

Conditional Structures

Davis Brown edited this page Aug 28, 2018 · 5 revisions

SQF++ supports the standard set of conditional structures, although with a more traditional syntax.

Every conditional structure (Except switch) also supports a single statement, non-block alternative.

if (true) _x = player();

If-Else

if (5 < 1) {
    // if true ..
}

if (5 < 1) {
    // if true ..
} else {
    // if false ..
}

Else-if

if (5 < 1) {

} else if (5 < 2) {

} else if (5 < 3) {

} else {

}

For-Loops

Indexed For-Loop

for(var _i = 0; _i < 10; _i += 1) {
    _i *= 2;
}

Foreach-Loop

for(var _element : _list) {
    // _element refers to the currently iterated element
}

While-Loops

var _x = 0;`

while (_x < 5) {
    _x += 1;
}

Switch

switch (5) {

    case 0: {
        // ..
        break;
    }

    case 5: {
        // ..
        break;
    }

    default: {
        // ..
    }

}
Clone this wiki locally