{"name":"then","operator":null,"title":"then","type":"command","url":"https://community.bistudio.com/wiki/then","revid":351752,"updated":"2024-01-03T10:15:29Z","groups":["Program Flow"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.85"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.85"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"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.\n\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","since":null,"effect":null,"exec":null,"params":[{"name":"ifType","type":"If Type","optional":false,"default":null,"description":null,"types":["If Type"],"since":null,"text":"ifType: If Type"},{"name":"thenCode","type":"Code or Array of Code:","optional":false,"default":null,"description":"Code or Array of Code:\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","types":["Code","Array"],"since":null,"text":"thenCode: Code or Array of Code:\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","types":["Anything"],"description":"result of the executed code","text":"Anything - result of the executed code"},"form":"binary","operator":null,"left":{"text":"ifType","types":["If Type"]},"right":{"text":"thenCode","types":["Code","Array"]}}],"examples":[{"text":"```sqf\nif (a > b) then { hint \"a is greater than b!\"; };\n```","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};"]},{"text":"```sqf\nif (alive player) then [{ hint \"player is alive\"; }, { hint \"player is dead\"; }];\n```","code":["if (alive player) then [{ hint \"player is alive\"; }, { hint \"player is dead\"; }];"]},{"text":"```sqf\nprivate _value = if (alive player) then { 1 } else { 0 };\n```","code":["private _value = if (alive player) then { 1 } else { 0 };"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["Control Structures","if","else"],"notes":[],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Program Flow","Introduced with Operation Flashpoint version 1.85","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}