Hello and welcome to the GDScript fundamental tutorial series.
In this episode, I go over for loops in Godot GDScript.
A for loop is a control flow statement that allows code to be executed repeatedly.
This type of loop allows for the enumeration (iteration) of sets of items other than a sequence of numbers.
For starters, you can loop through literal integers:
for x in 10:
print(x)
The numbers 1 - 10 will print to the console in the Godot application in the script above.
var arrayExample = [10,20,30]
for x in arrayExample:
print(x)
In the script above, the numbers 10, 20, and 30 will print to the console.
You will use a for-loop when you want to have an array or dictionary item you’d like to iterate over.