For in Chapel
Chapel provides several ways to create loops. Here are some basic types of loops.
When you run this program, you’ll see:
In Chapel, the for
loop is more versatile than in many other languages. It can iterate over ranges, arrays, and other iterable objects. The while
loop is used for condition-based looping.
The ..#
syntax in Chapel creates a range from 0 to n-1, which is similar to the range-based for loops in the original example.
Chapel doesn’t have a direct equivalent to Go’s for range
over an integer, but using a range with ..#
achieves the same result.
We’ll see other forms of loops later when we look at iterating over arrays, domains, and other data structures.