The expression is tested at the top of the loop (while)

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.

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.