Skip to content

Commit c13a37e

Browse files
author
Alex Razoumov
committed
introduce a very simple loop to show range usage
1 parent bd3d7e6 commit c13a37e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

episodes/03-ranges-arrays.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ exercises: 30
1515
## Ranges and Arrays
1616

1717
A series of integers (1,2,3,4,5, for example), is called a **_range_**. Ranges are generated with the `..`
18-
operator. Let's examine what a range looks like (`ranges.chpl` in this example):
18+
operator. Let's examine what a range looks like; we store the following code as `ranges.chpl`. Here we
19+
introduce a very simple loop, cycling through all elements of the range and printing their values (we will
20+
study `for` loops in a separate section):
1921

2022
```chpl
2123
var example_range = 0..10;
2224
writeln('Our example range was set to: ', example_range);
25+
for x in example_range do writeln(x);
2326
```
2427

2528
```bash
@@ -29,6 +32,11 @@ chpl ranges.chpl
2932

3033
```output
3134
Our example range was set to: 0..10
35+
0
36+
1
37+
...
38+
9
39+
10
3240
```
3341

3442
Among other uses, ranges can be used to declare **_arrays_** of variables. An array is a multidimensional

0 commit comments

Comments
 (0)