<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/while(initialInputs:before:after:name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)whileWithInitialInputs:before:after:name:"
  },
  "title" : "while(initialInputs:before:after:name:)"
}
-->

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

Adds a while loop operation.

```
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

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)