The 'For' Loop


#1



https://www.codecademy.com/courses/ruby-beginner-en-XYcN1/1/1?curriculum_id=5059f8619189a5000201fbcb

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.


#2

The code in the excercise is:

for num in 1...10
  puts num
end

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.


#3

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