Consider the following two snippets of ruby code.
puts "One"
if false
d = 1
end
puts "Two"
puts d
puts "Three"
This prints the following
One
Two
Three
Now, consider the following
[].each do |i|
flag = false
end
puts "Two"
puts flag
puts "Three"
This gives the following
Two
'<main>': undefined local variable or method 'flag' for main:Object (NameError)
Why is it that in the first case a blank is printed and the 2nd case an error is thrown ?
Thanks