F# – while.do Loops

  • Post author:
  • Post category:F#
  • Post comments:2 Comments
F# - while.do Loops

The F# while.do Loops expression is used to perform iterative execution while a specified test condition is true.

Syntax F# while.do Loops

while test-expression do
   body-expression

The body expression must have a type unit, i.e., it should not return any value. If the test expression is false, the iteration ends.

Example

let mutable a = 10
while (a < 20) do
   printfn "value of a: %d" a
   a <- a + 1

When you compile and execute the program, it yields the following output −

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply