April 2018
Beginner
536 pages
13h 21m
English
The while expression is used to repeat an operation while a certain requirement is satisfied. For example, the following code snippet declares a numeric variable i. If the requirement (the value of i is less than 5) is satisfied, an operation takes place (increase the value of i by one and display its value in the browser console). Once the operation has completed, the accomplishment of the requirement will be checked again:
let i: number = 0;
while (i < 5) {
i += 1;
console.log(i);
}
In a while expression, the operation will take place only if the requirement is satisfied.