for loop is used to execute a code block over a given amount of time. This loop is very useful in Ocaml or other programming languages.
for var = initial_value to final_value do expression done
Let's look at the code below:
for i = 1 to 10 do print_int(i) done;;
In the above code, we use the
for loop to print all the numbers from
forloop and define the range for the loop
i = 1 to 10. The loop stops once
10. After the
dokeyword, we put the
code blockwe want to execute while the loop is running.
donekeyword to stop the
View all Courses