---
title: "for(numberOfIterations:initialBodyArguments:body:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/for(numberofiterations:initialbodyarguments:body:name:)"
---

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

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

## Declaration

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

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