The 'For' Loop


I just had a simple question about "num" that is used in this lesson. Is this a generic variable "num" that is already defined in Ruby? I'm having trouble understanding how the interpreter recognizes this and ties "num" to each value in the series when it reads the code "puts num".

Replace this line with your code.


The code in the excercise is:

for num in 1...10
  puts num

The "num" at the beginning of the for loop is, believe it or not, the making of the "num" variable! It is telling the computer to loop through 1...10 and store that value in num every iteration.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.