Skip to content

Commit

Permalink
Add while-true example
Browse files Browse the repository at this point in the history
  • Loading branch information
chenglou committed Mar 20, 2017
1 parent 39bb6cb commit bebc142
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,12 @@
#### While Loops
While loops are also fully imperative constructs. They execute a code block while
some condition is true. The form of a `while` loop includes a single expression,
the condition to test.
While loops are also fully imperative constructs. They execute a code block
while some condition is true. The form of a `while` loop includes a single
expression, the condition to test.
```reason
while testCondition {
while (testCondition) {
statements;
};
```
Expand All @@ -864,7 +864,21 @@
```reason
while true {
print_newline ();
print_endline "hello";
};
```
Example to break out of a while-true loop:
```reason
Random.self_init ();
let break = {contents: false};
while (not break.contents) {
if (Random.int 10 === 3) {

This comment has been minimized.

Copy link
@hcarty

hcarty Mar 23, 2017

Contributor

@chenglou This should be == correct?

This comment has been minimized.

Copy link
@chenglou

chenglou Mar 23, 2017

Author Member

Reason === is OCaml ==. This one compiles down to the JS === which is "correct". Though in this case, Reason == (OCaml =) also compiles down to JS === because it saw the int type I think.

Is this what you're talking about?

This comment has been minimized.

Copy link
@hcarty

hcarty Mar 23, 2017

Contributor

== in OCaml is structural equality which, while it works here because of the simple int to int comparison, it's a dangerous example to set because it is implementation dependent and wouldn't work for, say, boxed floats.

break.contents = true
} else {
print_endline "hello"
}
};
```
Expand Down

0 comments on commit bebc142

Please sign in to comment.