Skip to content

Commit 58188e5

Browse files
committed
Doc page for dropped do-while
This should have been part of the earlier PR.
1 parent 8ac2d3d commit 58188e5

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
layout: doc-page
3+
title: Dropped: Do-While
4+
---
5+
6+
The syntax construct
7+
```scala
8+
do <body> while <cond>
9+
```
10+
is no longer supported. Instead, it is recommended to use the equivalent `while` loop
11+
below:
12+
```scala
13+
while ({ <body> ; <cond> }) ()
14+
```
15+
For instance, instead of
16+
```scala
17+
do
18+
i += 1
19+
while (f(i) == 0)
20+
```
21+
one writes
22+
```scala
23+
while ({
24+
i += 1
25+
f(i) == 0
26+
}) ()
27+
```
28+
Under the [new syntax rules](../other-new-features/control-syntax), this code can be written also without the awkward `({...})` bracketing like this:
29+
```scala
30+
while {
31+
i += 1
32+
f(i) == 0
33+
} do ()
34+
```
35+
The idea to use a block as the condition of a while also gives a solution
36+
to the "loop-and-a-half" problem. For instance:
37+
```scala
38+
while {
39+
val x: Int = iterator.next
40+
x >= 0
41+
} do print(".")
42+
```
43+
44+
### Why Drop The Construct?
45+
46+
- `do-while` is used relatively rarely and it can expressed faithfully using just while. So there seems to be little point in having it as a separate syntax construct.
47+
- Under the [new syntax rules](../other-new-features/control-syntax) `do` is used
48+
as a statement continuation, which would clash with its meaning as a statement
49+
introduction.

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ sidebar:
143143
url: docs/reference/dropped-features/existential-types.html
144144
- title: Type Projection
145145
url: docs/reference/dropped-features/type-projection.html
146+
- title: Do-While
147+
url: docs/reference/dropped-features/do-while.html
146148
- title: Procedure Syntax
147149
url: docs/reference/dropped-features/procedure-syntax.html
148150
- title: Package Objects

0 commit comments

Comments
 (0)