-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
}; | ||
``` | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
chenglou
Author
Member
|
||
break.contents = true | ||
} else { | ||
print_endline "hello" | ||
} | ||
}; | ||
``` | ||
|
@chenglou This should be
==
correct?