Learning TypeScript 2.x
上QQ阅读APP看书,第一时间看更新

The expression is tested at the bottom of the loop (do...while)

The do...while expression can be used to repeat an instruction until a certain requirement is not satisfied. For example, the following code snippet declares a numeric variable i and repeats an operation (increase the value of i by one and display its value in the browser console) for as long as the requirement (the value of i is less than five) is satisfied:

let i: number = 0; 
do { 
  i += 1; 
  console.log(i); 
} while (i < 5); 

Unlike the while loop, the do...while expression will execute at least once, regardless of the tested expression, as the operation will take place before checking whether a certain requirement is satisfied or not.