vb2Py - For and For Each

Contents of this page:

Different forms:

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

VBPython

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

VBPython

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.