<!--
{
  "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/for(numberOfIterations:initialBodyArguments:body:name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)forLoopWithNumberOfIterations:initialBodyArguments:body:name:"
  },
  "title" : "for(numberOfIterations:initialBodyArguments:body:name:)"
}
-->

# for(numberOfIterations:initialBodyArguments:body:name:)

Adds a for loop operation, with a specific number of iterations.

```
func `for`(numberOfIterations: MPSGraphTensor, initialBodyArguments: [MPSGraphTensor], body: @escaping MPSGraphForLoopBodyBlock, name: String?) -> [MPSGraphTensor]
```

## Parameters

`numberOfIterations`

tensor with number of iterations the loop will execute

`initialBodyArguments`

initial set of iteration arguments passed to the bodyBlock of the for loop

`body`

bodyBlock, this will execute the body of the for loop, index will go from 0 to numberOfIterations-1

`name`

name of operation

## Return Value

A valid MPSGraphTensor array with same count and corresponding elementTypes as initialIterationArguments and return types of the for loop

---

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)