An algorithm of mine could be better readable if I could use a postcondition (do-until) loop instead of precondition (while) loop. Is there such a feature in Scala 2.8?
Scala - do-while Loop. Unlike while loop, which tests the loop condition at the top of the loop, the do-while loop checks its condition at the bottom of the loop. A do-while loop is similar to a while loop, except that a do-while loop is guaranteed to execute at least one time.
Sometimes a program is clearer to read (or understand) with more exact syntax. Scala's syntax is flexible. We can omit, or add, parentheses in for-to and until loops. Ranges. We can directly loop over the numbers in a Range. The first argument to Range is the start, the second is the exclusive end.
For to, until syntax. Sometimes a program is clearer to read (or understand) with more exact syntax. Scala's syntax is flexible. We can omit, or add, parentheses in for-to and until loops.
We can use the "to" method to advance through a range of numbers. We must choose the best loop. For example. Let us begin with a for-loop that enumerates a list. We create a list with 3 strings in it. Then we use the for-each loop on the list. Tip The syntax for a for-each loop in Scala is similar to that for Java.
Sure.
scala> var i = 0
i: Int#4363 = 0
scala> do {
| println(i)
| i += 1
| } while (i < 10)
0
1
2
3
4
5
6
7
8
9
res0: Unit#3773 = ()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With