---
url: /api/helpers/loop/functions/loop.md
---
# loop()

```ts
function loop(
  callback: (data: {
    time: number;
    deltaTime: number;
    elapsedTime: number;
  }) => void,
  params?: {
    immediate?: boolean;
  },
): {
  play: () => void;
  pause: () => void;
  stop: () => void;
};
```

Creates an animation loop that calls the provided callback on every animation frame.

## Parameters

### callback

(`data`: {
`time`: `number`;
`deltaTime`: `number`;
`elapsedTime`: `number`;
}) => `void`

A function that will be called on every animation frame.

### params?

parameters for the loop.

#### immediate?

`boolean`

If true, the loop will start immediately.

If false, the loop will start when the `play` method is called.

**Default**

```ts
true;
```

## Returns

An object with `play` and `pause` methods to control the animation loop.

| Name      | Type         | Description                                        |
| --------- | ------------ | -------------------------------------------------- |
| `play()`  | () => `void` | Play the animation loop.                           |
| `pause()` | () => `void` | Pause the animation loop.                          |
| `stop()`  | () => `void` | Stop the animation frame and unregister this loop. |
