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

8th Apr 2018, 5:25 PM
Ɓukasz Szczyglewski
Ɓukasz Szczyglewski - avatar
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.
8th Apr 2018, 5:57 PM
Vikash Pal
Vikash Pal - avatar
+ 3
Please post the question so we can help you
8th Apr 2018, 5:32 PM
Vikash Pal
Vikash Pal - avatar
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
8th Apr 2018, 5:40 PM
Ɓukasz Szczyglewski
Ɓukasz Szczyglewski - avatar
0
I didn't know why it don't check last relation
8th Apr 2018, 6:02 PM
Ɓukasz Szczyglewski
Ɓukasz Szczyglewski - avatar