如何在 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