---
name: "findIf"
type: command
status: ok
groups: ["Arrays"]
arma3_since: "1.82"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/findIf
revid: 376518
updated: 2025-10-22T23:13:13Z
---

# findIf

*Command · Arrays · Arma 3 v1.82*

## Description

Searches for an element within array for which the code evaluates to true. Returns the zero-based index on success or -1 if not found.

Code on the right side of the command is evaluated for each element of the array, processed element can be referenced in code as [_x](../topics/Magic_Variables.md#x).

> [!NOTE]
> [findIf](../commands/findIf.md) terminates as soon as it finds an element that fulfills the condition, thus it is more efficient than [count](../commands/count.md) in scenarios where a check for presence / absence of at least one element should be done (See [#Example 2](../commands/findIf.md#example-2)).

## Syntax

```sqf
array findIf code
```

**Parameters:**

- `array`: [Array](../topics/Array.md) - array to search in
- `code`: [Code](../topics/Code.md) - code defining an element to find, processed element can be referenced within the code as [_x](../topics/Magic_Variables.md#x)

**Returns:** [Number](../topics/Number.md) - zero-based position of the first array element for which the code evaluate to true, -1 if not found

## Examples

### Example 1

```sqf
private _firstDead = [unit1, unit2, unit3] findIf { not alive _x }; // return index of the first dead unit
```

### Example 2

```sqf
// two ways how to 'wait for all units to be dead':
waitUntil { [unit1, unit2, unit3] findIf { alive _x } == -1 };    // fast, terminates as soon as it finds a living unit
waitUntil { { alive _x } count [unit1, unit2, unit3] == 0 };    // slow, always goes through all array elements
```

## See also

[find](../commands/find.md) · [count](../commands/count.md)

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