# WaitWhile

> Suspends the coroutine execution until the supplied delegate evaluates to false.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine](/engine/6000.5/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule
* **Inherits from:** [CustomYieldInstruction](/engine/6000.5/script-reference/unityengine/customyieldinstruction.md)
* **Implements:** [IEnumerator](https://learn.microsoft.com/dotnet/api/system.collections.ienumerator)

```csharp
public sealed class WaitWhile : CustomYieldInstruction, IEnumerator
```

## Remarks

`WaitWhile` can only be used with a `yield` statement in coroutines.

The supplied delegate is executed each frame after [MonoBehaviour.Update()](/engine/6000.5/script-reference/unityengine/monobehaviour/update.md) and before [MonoBehaviour.LateUpdate()](/engine/6000.5/script-reference/unityengine/monobehaviour/lateupdate.md). When the delegate evaluates to `false`, the coroutine resumes.

```csharp
using UnityEngine;
using System.Collections;

public class WaitWhileExample : MonoBehaviour
{
    public int frame;

    void Start()
    {
        StartCoroutine(Example());
    }

    IEnumerator Example()
    {
        Debug.Log("Waiting for prince/princess to rescue me...");
        yield return new WaitWhile(() => frame < 10);
        Debug.Log("Finally I have been rescued!");
    }

    void Update()
    {
        if (frame <= 10)
        {
            Debug.Log("Frame: " + frame);
            frame++;
        }
    }
}
```

Additional Resources: [AsyncOperation](/engine/6000.5/script-reference/unityengine/asyncoperation.md), [WaitForEndOfFrame](/engine/6000.5/script-reference/unityengine/waitforendofframe.md), [WaitForFixedUpdate](/engine/6000.5/script-reference/unityengine/waitforfixedupdate.md), [WaitForSeconds](/engine/6000.5/script-reference/unityengine/waitforseconds.md), [WaitForSecondsRealtime](/engine/6000.5/script-reference/unityengine/waitforsecondsrealtime.md), [WaitUntil](/engine/6000.5/script-reference/unityengine/waituntil.md).

## Constructors

| Constructor                                                                                                                                                                                                              | Description                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- |
| [WaitWhile(System.Func\{System.Boolean})](/engine/6000.5/script-reference/unityengine/waitwhile/ctor.md#waitwhile\(funcbool\))                                                                                           | Initializes a yield instruction with a given delegate to be evaluated. |
| [WaitWhile(System.Func\{System.Boolean},System.TimeSpan,System.Action,UnityEngine.WaitTimeoutMode)](/engine/6000.5/script-reference/unityengine/waitwhile/ctor.md#waitwhile\(funcbool-timespan-action-waittimeoutmode\)) | Initializes a yield instruction with a given delegate to be evaluated. |

## Inheritance

**Inherited Members:**

* [CustomYieldInstruction.keepWaiting](/engine/6000.5/script-reference/unityengine/customyieldinstruction/keepwaiting.md)
