【发布时间】:2018-07-22 12:41:10
【问题描述】:
我理解这是如何工作的,因为我希望我已经在 cmets 中说明了这一点,但是我正在寻找一个技术性的信息,即:在第 3 行中,变量 [n] 被传递到第 3 行方括号格式,在方括号中传递 [n] 的正确术语是什么,例如括号表示法?或者那是错误的,是先计算方括号中的 n,然后将计算值传递给第 3 行的表达式的其余部分?
while (total < 10) // Line 1: while total is less than 10
{ n++; // Line 2: increment the variable n by 1 each time the loop executes
total += values[n]; // Line 3: Adds the value of an expression to the value
//of a variable and assigns the result to the variable.
}
【问题讨论】:
-
n是一个数组索引,values是一个数组。所以values由很多元素组成,[n]`指的是n-th一个。对“JavaScript 中的数组”进行 Google 搜索。数组是大多数计算机语言中常见的数据结构,索引语法也相当普遍。 -
好的,感谢您朝正确的方向轻推。