while 循环的目的是只要表达式为真,就重复执行语句或代码块。一旦表达式变为假,循环就会终止。示例您可以尝试运行以下代码来学习如何使用嵌套 while 循环在线演示 var height = 2; var width = 8; var col = 0; var row = 0; document.write("Starting Loop "); while (row < height) { col = 0; while(col < width) { document.write("#"); col++; } document.write(""); row++; } document.write("Loop stopped!");