TypeScript While Loop Statement

The while statement or loop will execute a block of code while a given condition is true.

Syntax

while (variable<=endvalue) {
    //code block to be executed
}

Note: The <= could be anything that would fit the purpose ex. >, == or whatever.

TypeScript While Loop Example 1

Display(temp:number):number
{
	var s : any = "";
	var x = 0;
	while (temp > x) {
		 s = s + "\n O is - " + x;
		 x++;
	}
return s;    
}
								
Try it Yourself

The while loop sets x equal to 0. As long as x is less than temp, the loop will continue to run. x will increase by 1 each time the loop runs.