1. The following syntax is correct for if conditional statement.
if condition
code
end
2. If expression.
The expression can be of which type?
3.What error does the if condition gives if not terminated with end statement?
4.What is the output of the following?
if 1<2
print "one is less than two"
end
5. What is the output of the code?
if 11<2
print "Eleven is less than two"
end
print "11 is greater"
6. What is the output of the given code?
if 11>2
puts "Eleven is greater than two"
end
print "You'r right"
7. What is the output of the given code?
if 79>78
puts "True".upcase
if 9>8
puts "True".reverse
if 7==7
puts "equal".downcase
end
end
end
8. What is the output of the given code?
if 79>78
puts "True".upcase
if 9>8
puts "True".Upcase
if 7==7
puts "equal".downcase
end
end
end
9. If statement inside if statement is called Nested if statements.
10. What is the output of the given code?
x=1
if x > 2
puts "x is greater than 2"
elsif x <= 2 and x!=0
puts "x is 1"
else
puts "I can't guess the number"
end