31. How many times will the following code segment display the message box? i =
ID: 3906080 • Letter: 3
Question
31. How many times will the following code segment display the message box?
i = 0
Do While i< 10
MessageBox.Show (“Hi”)
Loop
32. How many times will the following code segment display the message box?
i = 0 Do While i< 12
MessageBox.Show (“Hi”)
i += 3
Loop
33. How many times will the following code segment display the message box?
i = 0 Do While i<= 12
MessageBox.Show (“Hi”)
i += 3
Loop
34. How many times will the following code segment display the message box?
i = 100
Do While i< 10
MessageBox.Show (“Hi”)
i =+ 50
Loop
35. How many times will the following code segment will be executed?
i = 0
Do Until i = 10
i += 4
Loop
Explanation / Answer
NOTE: I have completed the program for your assignment. Please check and let me know if you have any questions. I will acknowledge back with a response within 24 hours. Thanks for your patience.
31. How many times will the following code segment display the message box?
i = 0
Do While i< 10
MessageBox.Show (“Hi”)
Loop
Explanation:
1) The above code will display the "Hi" message in message box infinitely.
2) The reason is there is no incrementation for i variable. So i variable never reaches 10 which is the terminating condition and always stuck at i = 0.
32. How many times will the following code segment display the message box?
i = 0 Do While i< 12
MessageBox.Show (“Hi”)
i += 3
Loop
Explnation:
1) The above code will display "Hi" message 4 times.
2) The first time i = 0 so it displays Hi. then it becomes 3 so it displays one more time. Then it becomes 6 and displays the message. Then it becomes 9 and displays the message. Finally when it becomes 12 the condition becomes false and it gets terminated.
3) So we can see the message display happened 4 times.
33. How many times will the following code segment display the message box?
i = 0 Do While i<= 12
MessageBox.Show (“Hi”)
i += 3
Loop
Explanation:
1) The above code will display "Hi" message 5 times.
2) The first time i = 0 so it displays Hi. then it becomes 3 so it displays one more time. Then it becomes 6 and displays the message. Then it becomes 9 and displays the message. Then it becomes 12 and the condition is true again because i can also be equal to 12. Finally when it becomes 15 the loop condition is false and terminated.
3) So we can see the message display happened 5 times.
34. How many times will the following code segment display the message box?
i = 100
Do While i< 10
MessageBox.Show (“Hi”)
i =+ 50
Loop
Explanation:
1) The above code will not display any message.
2) the reason is initial value of i is 100 and when the loop condition checked it is false. Because in order to enter into loop the i value should be less than 10.
3) Hence there is no message display happens.
35. How many times will the following code segment will be executed?
i = 0
Do Until i = 10
i += 4
Loop
Explanation:
1) The above code will execute infinitely because i never becomes 10.
2) Initially i value is 0 and loop iterates until i value is equal to 10.
3) In the first iteration i value increments to 4 then in second iteration 8 and in third iteration it becomes 12. If we see after third iteration the value becomes 12 which is not equal to 10 and it keeps going like that.
4) So the loop never terminates and it executes infinite number of times.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.