如何在 Javascript 中使用嵌套 while 循环?
while 循环的目的是在表达式为 true 的情况下重复执行一条语句或代码块。一旦表达式变为 false,循环就终止。
示例
你可以尝试运行下列代码来学习如何使用嵌套 while 循环
<html>
<body>
<script>
var height = 2;
var width = 8;
var col = 0;
var row = 0;
document.write("Starting Loop<br> ");
while (row < height) {
col = 0;
while(col < width) {
document.write("#");
col++;
}
document.write("<br>");
row++;
}
document.write("Loop stopped!");
</script>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP