---
name: "BIS_fnc_loop"
type: function
status: ok
groups: ["Program Flow"]
arma3_since: "1.16"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/BIS_fnc_loop
revid: 328958
updated: 2022-07-18T10:58:38Z
---

# BIS_fnc_loop

*Function · Program Flow · Arma 3 v1.16*

## Description

Loop stacked code/function with timing and conditional control. Code and conditions are executed in [non-scheduled environment](../topics/Scheduler.md#unscheduled_environment).

## Syntax

```sqf
[action, parameters] call BIS_fnc_loop
```

**Parameters:**

- `action`: [String](../topics/String.md) - can be one of:
  - "initialize" - Initializes game loop (not required as internal AUTO_INITIALIZE variable is set to true)
  - "terminate" - Terminates game loop (required as internal AUTO_TERMINATE variable is *not* set to true)
  - "itemAdd" - Adds an item to loop
  - "itemRemove" - Remove item from loop with id "uniqueId"
  - *"onEachFrame" - internally used by "initialize"*
  - *"itemExecute" - internally used by "onEachFrame"*
- `parameters`: [Array](../topics/Array.md) - used with "itemAdd" and "itemRemove" *action* ("itemRemove" only takes id):
  - id: [String](../topics/String.md) - loop unique id
  - code: [Code](../topics/Code.md) or [String](../topics/String.md) - code to be executed
  - timer: [Number](../topics/Number.md) - (Optional, default 0) delay between executions
  - timerType: [String](../topics/String.md) - (Optional, default "seconds") can be "seconds" or "frames"
  - conditionStart: [Code](../topics/Code.md) - (Optional, default `{ true }`) will *wait* until the condition is met to start the code
  - conditionEnd:  [Code](../topics/Code.md) - (Optional, default `{ false }`) stops the loop as soon as the ending condition is met (after the end of *code*)
  - executeOnce: [Boolean](../topics/Boolean.md) - (Optional, default [false](../commands/false.md))

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

## Examples

### Example 1

```sqf
// hints time every five seconds
["itemAdd", ["uniqueId", { hint str time; }, 5]] call BIS_fnc_loop;
```

### Example 2

```sqf
// removes stacked loop with id of uniqueId
["itemRemove", ["uniqueId"]] call BIS_fnc_loop;
```

### Example 3

```sqf
// hints time every frame after BIS_variable is assigned
["itemAdd", ["uniqueId", { hint str time; }, nil, nil, { !isNil { BIS_variable } }]] call BIS_fnc_loop;
```

### Example 4

```sqf
// hints time every five seconds after BIS_variable is assigned
["itemAdd", ["uniqueId", { hint str time; }, 5, "seconds", { !isNil { BIS_variable } }]] call BIS_fnc_loop;
```

### Example 5

```sqf
// hints time every frame
["itemAdd", ["uniqueId", { hint str time; }]] call BIS_fnc_loop;
```

### Example 6

```sqf
// remove item from loop with id "uniqueId"
["itemRemove", ["uniqueId"]] call BIS_fnc_loop;
```

## See also

[for](../commands/for.md) · [forEach](../commands/forEach.md) · [while](../commands/while.md)

<sub>Source: [BI Community Wiki — BIS fnc loop](https://community.bistudio.com/wiki/BIS_fnc_loop) (revision 328958).</sub>
