Indefinite Loop - While and Loop
This lesson will discuss two indefinite loop: While and Loop.
We'll cover the following...
We'll cover the following...
While loop
While loop also iterates until a specific condition is reached. However, in the case of a while loop, the number of iterations is not known in advance.
Syntax
The while keyword is followed by a condition that must be true for the loop to continue iterating and then begins the body of the loop.
The general syntax is :
Example
The following example makes use of a while loop to print a variable value. The loop terminates when the variable’s value modulus 2 equals 1.
Explanation
- A mutable variable,
var, is defined on line 2. - A mutable