mason

for

for allows for simple loops.

break will end the loop.

n = 0
for
	n := + 1 n
	if =? n 5
		break
n

Loops can be values instead of statements.

Just provide a value to break.

n = 0
for
	n := + 1 n
	if =? n 10
		break n

You can also loop over a collection.

If you provide no element name, it will be _.

. 0
for n of 1..3
	. n
for 4..99
	. _
	if =? _ 5
		break

@for

Often you want to create a collection from a loop.

Just use @for and the whole loop will be a builder.

@for [1 2 3 4]
	if divisible? _ 2
		. _

If you're not writing a complicated block, consider using functions like each! and @map, combined with &, to fit it all on one line.

. @map ['foo 'bar 'baz] &toUpperCase
. @keep [1 2 3 4] &(divisible? _ 2)
There's also a third kind of loop, $for!