Why don't these string expressions print the same result?
2 answers
The first one writes the string "abc", concatenated to itself five times:
"abc"*5 = "abc"+"abc"+"abc"+"abc"+"abc" = "abcabcabcabcabc"
The second part of the code writes "abc" using puts 5 times. The puts function writes a newline character after each message, which means it writes "abc \ n" 5 times.
5.times do puts "abc"
turns into
puts "abc" ->also jumps to the next line
puts "abc" ->also jumps to the next line
puts "abc" ->also jumps to the next line
puts "abc" ->also jumps to the next line
puts "abc" ->also jumps to the next line
+6
source to share