laylight tour
0/25
1/4

Loops and values · 1 of 4

For loops

for repeats a block of statements:

for i in 0..4 {
    place Pad at (i * 100um, 0)
}

0..4 is a range of integers from 0 up to, but not including, 4, so the loop runs with i = 0, 1, 2 and 3. A loop can also walk through a list: for x in [0, 30um, 70um] { ... }.

Loops go wherever statements go: into place { } blocks for instances and into layer blocks for shapes. A shape defined inside a loop is a new shape in every round, so each one can be placed:

layer si {
    for i in 0..3 {
        shape rect with 1um, 1um as dot
        place dot at (i * 2um, 0)
    }
}

In the same way, a name given with as inside a loop belongs to its own round.

Instances in a regular grid, like the ones a loop tends to produce, are written to GDSII as a single array reference.

Exercise

Make PadArray place count pads in a row, pitch apart, the first at the origin. Use a for loop, so that it works for any value of the parameters.

loading compiler…

Edit the code, watch the layout, then press Submit to check your solution against the exercise.

Compiling…