0
Why the answer on last question is 4 when there is true for num==8 also?
Previous screen tutorial shows situation when two cases for if are true then two strings are printed. correct me if i'm wrong
4 Answers
+ 4
Ćukasz Szczyglewski In ruby, each if statement starts with 'if' and ends with 'end' keyword. So your code with identation is :-
num = 8
if num>4
puts "4"
if num<7
puts "7"
if num==8
puts "8"
end
end
end
First if blick checks if num is greater than 4. This is true so it prints "4".
Then there is a nested if block that checks if num is lesser than 7. This is false. So it exits the if block. Hence answer is 4.
+ 3
Please post the question so we can help you
0
In ruby there is a question:
Whatis the output of this code?
num=8
if num>4
puts "4"
if num<7
puts "7"
if num==8
puts "8"
end
end
end
the right answer is 4 but in my opinion should be 48
0
I didn't know why it don't check last relation