0 votes

I ever see codes like:

for i in 10:
    # do something
in Engine by (671 points)

1 Answer

0 votes
Best answer

for is used to create a loop that iterates through a range of values. The most common form is a loop to count through numeric values:

for i in range(10):

This would print the numbers from 0 through 9.

The form you quoted above is an abbreviation. If you omit the range() function GDScript will assume it.

Note you can also iterate through arrays, strings, and dictionaries as well.

See here for more details:

by (20,899 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.