I wrote a program which had if...else if inside a do..end block in Ruby. Something like this:
[1..100].each do |num|
if num % 3 == 0 and num % 5 == 0
tf += 1
else if num % 3 == 0 and num % 5 != 0
t += 1
end
end
end
My question is: why is it necessary to put three ends at the end? From what is shown in the Ruby Wikibook, the if..else if requires only one end and the do..end requires only one end too.
The
else ifopens a new block. Useelsifto chain if and else clauses.