Skip to main content

for

for .. in loop

Loop through each item of an array, or list of values/objects.

Here is an example:

from "std" import *

vcc = supply("VCC")
gnd = dgnd()

at vcc
wire right 100

# Loop through an array of colors
for i in ["yellow", "red", "blue", "green", "purple"]:
add led(i) pin 2
wire right 100

add res(10k)

wire right 100 down 100
to gnd
VCC12D1_1yellow12D1_2red12D1_3blue12D1_4green12D1_5purpleR110kGND

You can also use the range(start, end) built-in method to create multiple items:

from "std" import *

vcc = supply("VCC")
gnd = dgnd()

at vcc
wire right 100

# Loop through an array of colors
for i in range(0, 5):
add led("GREEN") pin 2
wire right 100

add res(10k)

wire right 100 down 100
to gnd
VCC12D1_1GREEN12D1_2GREEN12D1_3GREEN12D1_4GREEN12D1_5GREENR110kGND