{"name":"then","title":"then","type":"command","url":"https://community.bistudio.com/wiki/then","revid":351752,"updated":"2024-01-03T10:15:29Z","groups":["Program Flow"],"status":"ok","games":{"ofp":"1.85","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.85","arma3_since":"0.50","description":"Links an If Type with Code to be executed if said If Type's condition is true; otherwise, \"else\" code is executed if provided.\nThe alternative syntax allows to set \"then\" code and \"else\" code in one array.\n\n> [!NOTE]\n> Variables declared inside *thenCode* are private to that code block - see Variables - Local Variables Scope.","syntaxes":[{"syntax":"ifType then thenCode","params":[{"name":"ifType","type":"If Type","type_expr":"If Type"},{"name":"thenCode","type":"Code or Array of Code:","description":"Code or Array of Code:\n\n- Code - code block to execute if *ifType*'s condition is true\n- Array of Code - array of two Code elements in format [thenCode, elseCode]; see Example 3","type_expr":"Code | Array<Code>","text":"thenCode: Code or Array of Code:\n\n- Code - code block to execute if *ifType*'s condition is true\n- Array of Code - array of two Code elements in format [thenCode, elseCode]; see Example 3"}],"returns":{"type":"Anything","type_expr":"Anything","description":"result of the executed code"},"form":"binary","left":{"text":"ifType"},"right":{"text":"thenCode"}}],"examples":[{"code":["if (a > b) then { hint \"a is greater than b!\"; };"]},{"text":"```sqf\nprivate _c = 0;\nif (_a > _b) then\n{\n    _c = 1;\n}\nelse\n{\n    _c = 2;\n};\n```","code":["private _c = 0;\nif (_a > _b) then\n{\n\t_c = 1;\n}\nelse\n{\n\t_c = 2;\n};"]},{"code":["if (alive player) then [{ hint \"player is alive\"; }, { hint \"player is dead\"; }];"]},{"code":["private _value = if (alive player) then { 1 } else { 0 };"]}],"see_also":["Control Structures","if","else"]}