Ruby interview questions part 12

Ruby interview questions part 12

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. If statement inside if statement is called Nested if statements.

Correct Answer is : TRUE

2. 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

Correct Answer is : x is 1

3. It’s a good habit to give two spaces between if statement and condition.

Correct Answer is : TRUE

4. Syntax for unless conditional statement is unless conditional [then] code else code end

Correct Answer is : TRUE

5. What is the output of the given code? x=3 unless x>2 puts "x is less than 2" else puts "x is greater than 2" end

Correct Answer is : x is greater than 2

6. What is the output of the given code? var = 1 print "1 -- Value is set\n" if var print "2 -- Value is set\n" unless var var = false print "3 -- Value is set\n" unless var

Correct Answer is : 1–Value is set

7. What is the output of the given code? hungry=false unless hungry print "Not hungry" else print "Hungry" end

Correct Answer is : Not hungry

8. The following syntax is also used for unless conditional statement. code unless conditional

Correct Answer is : TRUE

9. What is the output of the given code? counter=12 unless counter print counter+1 else print counter+2 end

Correct Answer is : 14

10. What is the output of the given code? unless true && false print "false" else print "ruby" end

Correct Answer is : FALSE

11. What is the output of the given code? print "2 is less than 3" unless 2>3

Correct Answer is : 2 is less than 3

12. What is the output of the given code? x=8 y=10 unless x>y puts "x is less than y" end unless x>y+1 puts "x is less than y+1" end

Correct Answer is : x is less than y

13. What is the output of the given code? x="ruby".length y="language".length puts x,y unless x>y print "length of x is less than that of y" end

Correct Answer is : 4

14. What is the output of the given code? x=8 y=10 unless xy+1 puts "x is less than y+1" end

Correct Answer is : x is less than y+1

15. The complement of while loop is until loop.

Correct Answer is : TRUE

16. What is the output of the given code? counter = 1 until counter > 10 puts counter counter+=1 end

Correct Answer is : 1 2 3 4 5 6 7 8 9 10

17. What is the output of the given code? counter = 0 until counter >= 10 puts counter counter+=1 end

Correct Answer is : 0 1 2 3 4 5 6 7 8 9

18. What is the output of the given code? i = 3 while i > 0 do puts i i -= 1 end   j = 3 until j == 0 do puts j j -= 1 end

Correct Answer is : 0 1 2 3 4 5 6 7 8 9

19. What is the output of the given code? a="hungry" until !a puts "hungry" a=!a end

Correct Answer is : hungry

20. What is the output of the given code? m= 8 loop do m += 2 puts m break if m == 16 end

Correct Answer is : 10 12 14 16

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon