---
title: "while(initialInputs:before:after:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/while(initialinputs:before:after:name:)"
---

# while(initialInputs:before:after:name:)

Adds a while loop operation.

## Declaration

```swift
func `while`(initialInputs: [MPSGraphTensor], before: @escaping MPSGraphWhileBeforeBlock, after: @escaping MPSGraphWhileAfterBlock, name: String?) -> [MPSGraphTensor]
```

## Parameters

- `initialInputs`: inputTensors to the beforeBlock, for the 1st iteration will be same as initialInputs passed to the while loop.
- `before`: beforeBlock, this will be run first and then call the afterBlock with results or return results from the loop.
- `after`: afterBlock, this will execute after the condition evaluation.
- `name`: Name of operation.

## Return Value

Return Value A valid MPSGraphTensor array with results returned from the conditionBlock depending on the predicate tensor.
