I want to know the name of the "temporary variable" that you access inside a for-loop. It's not really language-specific, but here's my code in Swift:
let array = [1, 2, 3]
for number in array {
print(number) /// what is this?
}
What is number
, the "temporary variable" that is different in each iteration, known as?
Here are my attempts at describing it.
- The current iteration's element
- The current element
Then, what if I was looping over the array's indices? How would I refer to number
in this case?
let list = [1, 2, 3]
for i in 0..<list.count {
let number = list[i] /// what is this?
print(number)
}
My attempts:
- The element of the
list
array at the current iteration's index - The element of the
list
array at the loop's current iteration's index