Skip to content
Narta Xaymar Dirks edited this page Nov 1, 2026 · 4 revisions

Blitz3DBlitzPlusBlitzBasic

For

For variable = from To limit [Step amount]
statements
Next
For variable.Type = Each Type
statements
Next

Description

Counts variable from from up to limit, running the statements once for each number. With Step it changes by that amount instead of 1, and counts down when the amount is negative. The limit is worked out again before every pass, so changing a variable that it uses changes how often the loop runs, while the step is worked out once. The variable has to be a number, but a real number (Float) does not count exactly: the loop may run once more or less than expected, or never end (warning loop-iterator-type-unsafe). The start, limit and step are turned into the type of the variable: a Byte that counts to a limit above 255 never gets there, and the loop never ends (warning loop-type-mismatch). Next ends the loop. For ... = Each walks through all objects of a custom type instead.

Examples

For i = 1 To 3
	Print i
Next
For i = 10 To 1 Step -4
	Print i
Next
1
2
3
10
6
2

Related Commands

Exit, Forever, Next

Home · Command Index



Differences
Language Features
BlitzBasic
Blitz3D
BlitzPlus

Clone this wiki locally