@@ -1991,28 +1991,19 @@ way.
1991
1991
1992
1992
* TODO* .
1993
1993
1994
- ### While expressions
1994
+ ### While loops
1995
1995
1996
1996
~~~~~~~~ {.ebnf .gram}
1997
1997
while_expr : "while" expr '{' block '}'
1998
1998
| "do" '{' block '}' "while" expr ;
1999
1999
~~~~~~~~
2000
2000
2001
- A ` while ` expression is a loop construct. A ` while ` loop may be either a
2002
- simple ` while ` or a ` do ` -` while ` loop.
2001
+ A ` while ` loop begins by evaluating the boolean loop conditional expression.
2002
+ If the loop conditional expression evaluates to ` true ` , the loop body block
2003
+ executes and control returns to the loop conditional expression. If the loop
2004
+ conditional expression evaluates to ` false ` , the ` while ` expression completes.
2003
2005
2004
- In the case of a simple ` while ` , the loop begins by evaluating the boolean
2005
- loop conditional expression. If the loop conditional expression evaluates to
2006
- ` true ` , the loop body block executes and control returns to the loop
2007
- conditional expression. If the loop conditional expression evaluates to
2008
- ` false ` , the ` while ` expression completes.
2009
-
2010
- In the case of a ` do ` -` while ` , the loop begins with an execution of the loop
2011
- body. After the loop body executes, it evaluates the loop conditional
2012
- expression. If it evaluates to ` true ` , control returns to the beginning of the
2013
- loop body. If it evaluates to ` false ` , control exits the loop.
2014
-
2015
- An example of a simple ` while ` expression:
2006
+ An example:
2016
2007
2017
2008
~~~~
2018
2009
# let mut i = 0;
@@ -2024,18 +2015,6 @@ while i < 10 {
2024
2015
}
2025
2016
~~~~
2026
2017
2027
- An example of a ` do ` -` while ` expression:
2028
-
2029
- ~~~~
2030
- # let mut i = 0;
2031
- # let println = io::println;
2032
-
2033
- do {
2034
- println("hello\n");
2035
- i = i + 1;
2036
- } while i < 10;
2037
- ~~~~
2038
-
2039
2018
### Infinite loops
2040
2019
2041
2020
A ` loop ` expression denotes an infinite loop:
0 commit comments