假设当第一个 if 语句和 else 语句中的嵌套 if 都失败时,我是否正确,然后我回到第一个 for 循环并递增i
1?
所以我可以继续直到 j < totalCols 失败,即使 if 或 else 语句都没有执行?
var rowCount = [];
for (var i = 0; i < totalRows; i++) {
rowCount[i]="";
spaceCount = 0;
for (var j = 0; j < totalCols; j++) {
if (puzzle[i][j] == "#") { // if this fails?
spaceCount++;
if (j == totalCols-1) rowCount[i] += spaceCount + " ";
} else {
if (spaceCount > 0) { //and this fails?
rowCount[i] += spaceCount + " ";
spaceCount = 0;
}
}
}
}