Skip to content

Commit

Permalink
loop example
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot committed Jul 31, 2023
1 parent cd1ccc3 commit dcca0fc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions data/tutorials/language/1ds_01_arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ The `Array.length` function returns the size of an array:
0 0 0 0 0 - : unit = ()
```

Iterating on arrays can also be made using `for` loops. Here is the same example using a loop:

```ocaml
# for i = 0 to Array.length zeroes - 1 do
print_int zeroes.(i);
print_string " "
done;;
0 0 0 0 0 - : unit = ()
```

### Map an Array

The `Array.map` function creates a new array by applying a given function to each element of an array. For example, we can get an array containing the square of each number in the `even_numbers` array:
Expand Down

0 comments on commit dcca0fc

Please sign in to comment.