NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
# While Loop While Loops repetitively execute a block of code as long as a specified condition is true. ~~~ while(condition){ // do it as long as condition is true } ~~~ For example, the loop in this example will repetitively execute its block of code as long as the variable i is less than 5: ~~~ var i = 0, x = ""; while (i < 5) { x = x + "The number is " + i; i++; } ~~~ The Do/While Loop is a variant of the while loop. This loop will execute the code block once before checking if the condition is true. It then repeats the loop as long as the condition is true: ~~~ do { // code block to be executed } while (condition); ~~~ **Note**: Be careful to avoid infinite looping if the condition is always true! Exercise Using a while-loop, create a variable named `message` that equals the concatenation of integers (0, 1, 2, ...) as long as its length (`message.length`) is less than 100. ~~~ var message = ""; ~~~