我想问一下我下面的代码,当我使用for循环时,它没有像我预期的那样运行,它显示所有五个数据的结果总共是26,因为我想知道这里发生了什么。
function main() {
var levels = parseInt(5,10);
var points = new Array();
var count = 0;
while(count<levels){
var elem = [4,5,6,7,4]; // in total must be 26
points[count] = elem[count];
count++;
}
var sum = 0;
while(count<levels){
var sum = sum + points[count];
count++;
} // I can make it worked using for loop
console.log(sum)
}
main()
var sum = 0;
count = 0; // Reset count to 0
while(count<levels){
返回26