From bebc142cd3d9969773ee73037327601a5d4e063d Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Sun, 19 Mar 2017 19:38:09 -0700 Subject: [PATCH] Add while-true example --- docs/index.html | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/index.html b/docs/index.html index 1431b9e9f..c7397ff08 100755 --- a/docs/index.html +++ b/docs/index.html @@ -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) { + break.contents = true + } else { + print_endline "hello" + } }; ```