# vb2Py - For and For Each

Contents of this page:

- General
- Default Conversion
- List of Options

Different forms:

- For i = 0 To 10
- For Each Obj In Container

# General

`For` and `For Each` statements are converted to an equivalent Python for block. Where the iteration is over an iterable object, the translation just uses the iterable. Where the VB statement is an iteration between two numbers, the `vb2Py` function `vbForRange` is used to match the behaviour.

# Default Conversion

## For i = 0 To 10

VB | Python
--- | ---
    For i = 0 To 10
        DoSomething i
        If Condition Then Exit For
    Next i
        for i in vbForRange(0, 10):
            DoSomething(i)
            if Condition:
                break

## For Each Obj In Container

VB | Python
--- | ---
    For Each Obj In Container
        DoSomethingWith i
        If i.Condition Then Exit For
    Next i
        for i in Container:
            DoSomethingWith(i)
            if i.Condition:
                break

# List of Options

There are no options specific to the `For` statement.