<!--
{
  "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(lowerBound:upperBound:step: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)forLoopWithLowerBound:upperBound:step:initialBodyArguments:body:name:"
  },
  "title" : "for(lowerBound:upperBound:step:initialBodyArguments:body:name:)"
}
-->

# for(lowerBound:upperBound:step:initialBodyArguments:body:name:)

Adds a for loop operation, The lower and upper bounds specify a half-open range: the range includes the lower bound but does not include the upper bound.

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

## Parameters

`lowerBound`

Lower bound value of the loop, this is a scalar tensor, this is the index the loop will start with.

`upperBound`

Upper bound value of the loop, this is a scalar tensor.

`step`

Step value of the loop, this is a scalar tensor and must be positive.

`initialBodyArguments`

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

`body`

This block will execute the body of the for loop.

`name`

name of operation.

## Return Value

A valid `MPSGraphTensor` array with same count and corresponding element types 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)