Print "#{i}" vs. print i


#1



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


I understand this is the correct answer for me to proceed.

However, I'm having a bit of trouble understanding why we have print "#{i}" in the code rather than print i. What do they mean and how do they differ? Thanks!

i = 20
loop do
  i -= 1
  print "#{i}"
  break if i <= 0
end


#2

@cathyccc,
The phenomen is called interpolation
google search
== discussions / opinions ==
ruby interpolation site:stackoverflow.com
for instance
http://stackoverflow.com/questions/10091156/why-does-string-interpolation-work-in-ruby-when-there-are-no-curly-braces

http://stackoverflow.com/questions/26218555/ruby-interpolation


#3

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