F# – Nested Loops

  • Post author:
  • Post category:F#
  • Post comments:2 Comments
F# - Nested Loops

F# Nested Loops programming language allows using one loop inside another loop.

Syntax of F# Nested Loops

The syntax for a nested for loop statement could be as follows −

for var1 = start-expr1 to end-expr1 do
   for var2 = start-expr2 to end-expr2 do
      ... // loop body

The syntax for a nested while loop statement could be as follows −

while test-expression1 do while test-expression2 do body-expression

Example

let main() =
   for i = 1 to 5 do
      printf "\n"
      for j = 1 to 3 do
         printf "*"
main()

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

***
***
***
***
***

Next Topic – Click Here

This Post Has 2 Comments

Leave a Reply