{"name":"breakTo","title":"breakTo","type":"command","url":"https://community.bistudio.com/wiki/breakTo","revid":364900,"updated":"2024-06-29T14:38:35Z","groups":["Program Flow"],"status":"ok","games":{"arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma1 1.00","arma3_since":"0.50","description":"Breaks block to scope named *name*.\n\nScope name can be assigned using the scopeName command.","syntaxes":[{"syntax":"breakTo name","params":[{"name":"name","type":"String","type_expr":"String"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"unary","right":{"text":"name"}}],"examples":[{"text":"```sqf\nscopeName \"main\";\nwhile { true } do\n{\n    scopeName \"loop1\";\n    while { true } do\n    {\n        scopeName \"loop2\";\n        if (condition1) then { breakTo \"main\" };    // breaks all scopes and return to \"main\"\n        if (condition2) then { breakOut \"loop2\" };    // breaks scope named \"loop2\"\n        sleep 1;\n    };\n    sleep 1;\n};\n```","code":["scopeName \"main\";\nwhile { true } do\n{\n\tscopeName \"loop1\";\n\twhile { true } do\n\t{\n\t\tscopeName \"loop2\";\n\t\tif (condition1) then { breakTo \"main\" };\t// breaks all scopes and return to \"main\"\n\t\tif (condition2) then { breakOut \"loop2\" };\t// breaks scope named \"loop2\"\n\t\tsleep 1;\n\t};\n\tsleep 1;\n};"]}],"see_also":["scopeName","breakOut","exitWith"],"notes":[{"user":"Nelis75733126","date":"2017-05-18T18:19:00Z","text":"I wish to clarify the behaviour of this command by saying that the `breakTo` command will literally break the scope in which it has been placed, and continue reading whatever is after and outside of that scope.\nExample:\n\n```sqf\nscopeName \"something\";\nif true then\n{\n    breakTo \"something\";\n    _v = 0;    // this line will be skipped\n};\n\n_a = 0;        // this is where script execution will jump to.\n```"}]}