如何在 JavaScript 中使用巢狀 While 迴圈?
while 迴圈的目的是在表示式為真時重複執行語句或程式碼塊。一旦表示式變為假,則迴圈終止。
示例
你可以嘗試執行以下程式碼以瞭解如何使用巢狀 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>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP