Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

1. What is the output of the given code?

for num in 1...5
  puts num
end

a) 1 2 3 4 5
b) 1 2 3 4
c) 2 3 4 5
d) None of the mentioned

View Answer

Answer: b [Reason:] As the range i.e 1…10 is exclusive the loop will loop till 4 and then it will come out of the loop.

Output:
1
2
3
4

2. What does the 1…10 indicate?
a) Inclusive range
b) Exclusive range
c) Both inclusive and exclusive range
d) None of the mentioned

View Answer

Answer: b [Reason:] 1…10 means start from one and go till 9 and don’t include 10.

3. What is the output of the given code?

for num in 1..3
  puts num
  for i in 1..2
  puts num*i
  end
end

a) 1 2 3 4 5
b) 1 1 2 2 2 4 3 3 6
c) 2 3 4 5
d) None of the mentioned

View Answer

Answer: b [Reason:] This is a nested loop.

Output:
1
1
2
2
2
4
3
3
6

4. What is the output of the given code?

m= 0
loop do
    m += 1
    print m
    break if m == 10
end

a) 12345678910
b) 1 2 3 4
c) 2 3 4 5
d) None of the mentioned

View Answer

Answer: a [Reason:] Loop till the condition is met and break when the condition is not satisfied.

Output:
12345678910

5. What is the output of the given code?

for num in 1..5
  puts num*num
end

a) 12345678910
b) 1 2 3 4
c) 1 4 9 16 25
d) None of the mentioned

View Answer

Answer: c [Reason:] Loop till the condition is met and break when the condition is not satisfied.

Output:
1
4
9
16
25

6. What is the output of the given code?

for num in 1..3
  puts num*num
  m= 0
loop do
    m += 1
    puts m
    break if m == 3
end
end

a) 12345678910
b) 1 1 2 3 4 1 2 3 9 1 2 3
c) 1 4 9 16 25
d) None of the mentioned

View Answer

Answer: c [Reason:] Loop till the condition is met and break when the condition is not satisfied.

Output:
1
1
2
3
4
1
2
3
9
1
2
3

7. What is the output of the given code?

loop do
    m += 1
    puts m
    break if m == 3
end

a) Garbage values
b) 1 1 2 3 4 1 2 3 9 1 2 3
c) 1 4 9 16 25
d) None of the mentioned

View Answer

Answer: a [Reason:] Loop till the condition is met and break when the condition is not satisfied.

Output:
Garbage values

8. What is the output of the given code?

i=1
for i in 5..10
puts i^2
end

a) 7 4 5 10 11 8
b) 25 36 49 64 81 100
c) 1 4 9 16 25
d) None of the mentioned

View Answer

Answer: b [Reason:] Initialize the value of i and then print i**2.

Output:
25
36
49
64
81
100

9. What does the 1..10 indicate?
a) Inclusive range
b) Exclusive range
c) Both inclusive and exclusive range
d) None of the mentioned

View Answer

Answer: a [Reason:] 1..10 means start from one and go till 9 and even include 10.

10. What is the output of the given code?

i=5
j=10
for i in 5..10 && j in 5..10
puts i**j
end

a) Syntax error
b) 25 36 49 64 81 100
c) 1 4 9 16 25
d) None of the mentioned

View Answer

Answer: a [Reason:] Initialize the value of i and j and then when condition is true print i**j.

Output:
syntax error, unexpected keyword_in, expecting keyword_do_cond or ';' or 'n'
for i in 5..10 && j in 5..10 syntax error, unexpected keyword_end, expecting $end

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com