I’m trying to loop through 2 arrays, and notice some odd behaviour,
probably because the syntax is not correct
unsorted.each do |x|
sorted.each do |y|
puts 'this is que_words ’ + x + ‘.’
puts 'this is s_words ’ + y + ‘.’
end
end
I added the ‘puts’ in as I’m trying to build a bigger block of code
and trying to take it one step at a time with some checking in place.
unsorted has elements, sorted is empty.
When I run the above, nothing is output. When I comment out the
sorted loop, unsorted outputs it’s elements. Would having an empty
array effect the output of unsorted or is this just plain wrong ?
I added the ‘puts’ in as I’m trying to build a bigger block of code
and trying to take it one step at a time with some checking in place.
unsorted has elements, sorted is empty.
When I run the above, nothing is output. When I comment out the
sorted loop, unsorted outputs it’s elements. Would having an empty
array effect the output of unsorted or is this just plain wrong ?
Stuart
If sorted is empty it, never enters the sorted.each block, which is
where all the output is. Try this
unsorted.each do |x|
puts 'this is que_words ’ + x + ‘.’
sorted.each do |y|
puts 'this is s_words ’ + y + ‘.’
end
end
Okay …thanks! makes sense.
Apologies also for leaving the que_words and s_words in the puts
statement.
I meant to change them out since unsorted and sorted are easier to
understand.
Stuart
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.