---
name: "exitWith"
type: command
status: ok
groups: ["Program Flow"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/exitWith
revid: 379418
updated: 2026-10-31T00:03:53Z
---

# exitWith

*Command · Program Flow · Arma 3 v0.50 · introduced in Armed Assault v1.00*

## Description

Exits the **current** code scope. Often used for exiting [do](../commands/do.md), [for](../commands/for.md), [count](../commands/count.md), [forEach](../commands/forEach.md) or the whole script.

> [!NOTE]
> See [Variables - Local Variables Scope](../topics/Variables.md#local-variables-scope) for more information.

## Syntax

```sqf
ifType exitWith code
```

**Parameters:**

- `ifType`: [If Type](../topics/If_Type.md)
- `code`: [Code](../topics/Code.md)

**Returns:** [Anything](../topics/Anything.md)

## Examples

### Example 1

```sqf
systemChat "start";
private _condition = true;

if (_condition) then
{
    if (true) exitWith
    {
        systemChat "exiting if _condition scope";
    };
    systemChat "never shown";
};

systemChat "exiting #1 worked";

if (true) exitWith
{
    systemChat "exiting the main scope = leaving the whole script";
};

systemChat "never shown - the script has already ended";
```

### Example 2

```sqf
for "_j" from 1 to 10 do
{
    systemChat format ["%1", _j];

    // the for loop will cease and code execution will continue after the end of the loop
    if (_j == 5) exitWith
    {
        systemChat "5 is enough";
    };
};
systemChat "Complete";
```

### Example 3

Most loops will also terminate when their scope is exited. To exit and terminate scopes which are called every frame such as [onEachFrame](../commands/onEachFrame.md) and [waitUntil](../commands/waitUntil.md) use the following examples:

```sqf
onEachFrame {
    if (!alive player) exitWith
    {
        onEachFrame {};
    };
};
```

```sqf
_time = time + 10;
waitUntil
{
    if (time > _time) exitWith { true };
    false
};
```

### Example 4

```sqf
while { true } do
{
    if (alive player) then
    {
        if (time > 300) exitWith // [wrong] - it will only leave the "if alive player" scope, remaining in the "while true" loop forever
        {
            hint "exiting";
        };
    };
};
```

### Example 5

```sqf
if (_condition) exitWith
{
    hint "reached";
};
// else { hint "not reached" }; // [wrong] - using else does not work and makes no sense here
```

```sqf
if (_condition) exitWith
{
    hint "reached";
};
hint "not reached"; // [correct] - if _condition is met, the scope has already been exited by now
```

## See also

[scopeName](../commands/scopeName.md) · [breakOut](../commands/breakOut.md) · [breakTo](../commands/breakTo.md) · [else](../commands/else.md) · [Control Structures](../topics/Control_Structures.md) · [then](../commands/then.md) · [assert](../commands/assert.md) · [try](../commands/try.md) · [catch](../commands/catch.md) · [throw](../commands/throw.md)

## Community notes

**RoehrenRadio** — 2010-05-28

Since Arma 2 uses Blocks in FSM as any ordinary Handle like [while](../commands/while.md), [for](../commands/for.md) etc. in Scripts, **ExitWith** also only closes the Block in the FSM.

---

**Killzone_Kid** — 2013-08-04

The command will exit the current scope - no ifs no buts. If the current scope is a loop, it will exit the loop. If the current scope is the main body of a script, it will exit the script. For more understanding of scopes and [exitWith](../commands/exitWith.md) have a look at [this resource](http://killzonekid.com/arma-scripting-tutorials-scopes/).

---

**Killzone_Kid** — 2016-03-10

[exitWith](../commands/exitWith.md) cannot be used in event handlers with override ability to simply exit with override value. The following is incorrect:

```sqf
// INCORRECT USAGE
onMapSingleClick { if (!isServer) exitWith { true } };
```

The override value must be returned in the main scope of EH, but since it is exited with [exitWith](../commands/exitWith.md), it never happens. The correct way in this case would be:

```sqf
// CORRECT USAGE
onMapSingleClick { call { if (!isServer) exitWith { true } } };
```

[exitWith](../commands/exitWith.md) will exit current [call](../commands/call.md) scope only and override value therefore will appear in the main scope of the EH, right where we want it.

<sub>Source: [BI Community Wiki — exitWith](https://community.bistudio.com/wiki/exitWith) (revision 379418).</sub>
