godot for loop

# loop for n = 0 to 7
for n in range(8):
    print(n)

# loop for n = 10 to 12
for n in range(10,13):
    print(n)

# count down from 10 to 1
for n in range(10,0,-1):
    print(n)

# loop for n = 2,4,6,8 in steps of 2
for n in range(2,9,2):
    print(n)

# Iterate over string (array of characters)
for ch in "Hello":
    print(ch)

# Iterate over an array of numbers
for x in [3,6,8,9]:
    print(x)

# Iterate over items of a dictionary
var dict = { "x": 1, "y": 2, "z": 3 }
for key in dict:
    # Insert the key and value into a text string
    print("index: %s, value: %d" % [key, dict[key]])

# Using continue and break statements
for i in range(9):
    # Skip numbers below 3
    if i < 3:
        continue
    # Break out of the loop for numbers above 5
    if i > 5:
        break
    print(i)

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source