What is wrong with the following Do While loop? Dim index As Integer = 1 Do Whil
ID: 3763730 • Letter: W
Question
What is wrong with the following Do While loop?
Dim index As Integer = 1
Do While index <> 9
lstBox.Items.Add("Hello")
index += 2
Loop
(A) The test variable should not be changed inside a Do loop.
(B) The test condition will never be true.
(C) This is an infinite loop.
(D) Nothing
What numbers will be displayed in the list box when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num as Double = 10
Do While num > 1
lstBox.Items.Add(num)
num = num - 3
Loop
End Sub
(A) 10, 7, and 4
(B) 10, 7, 4, and 1
(C) 10, 7, 4, 1, and -2
(D) No output
Which While statement is equivalent to Until num < 100?
(A) While num <= 100
(B) While num > 100
(C) While num >= 100
(D) There is no equivalent While statement.
What is wrong with the following Do While loop?
Dim index As Integer = 1
Do While index <> 10
lstBox.Items.Add("Hello")
index += 1
Loop
(A) It should have been written with a Do Until loop.
(B) It is an infinite loop.
(C) The test variable should not be changed within the loop itself.
(D) Nothing wrong
How many times will this loop display “Hello” in the listbox?
Dim index as Integer=1
Do
lstBox.Items.Add(“Hello”)
index +=1
Loop Whileindex<7
In analyzing the solution to a program, you conclude that you want to construct a loop so that the loop terminates either when (a < 12) or when (b = 16). Using a Do loop, the test condition should be
(A) Do While (a > 12) Or (b <> 16)
(B) Do While (a >= 12) Or (b <> 16)
(C) Do While (a < 12) Or (b <> 16)
(D) Do While (a >= 12) And (b <> 16)
(E) Do While (a < 12) And (b = 16)
When Visual Basic executes a Do While loop it first checks the truth value of the _________.
(A) pass
(B) loop
(C) condition
(D) statement
If the loop is to be executed at least once, the condition should be checked at the __________.
(A) top of the loop
(B) middle of the loop
(C) bottom of the loop
(D) Nothing should be checked.
What will be displayed by the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim letter As String, s As String = ""
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
letter = sr.ReadLine
Do While letter <> "q"
s = letter & s
letter = sr.ReadLine
Loop
txtBox.Text = s
End Sub
The seven lines of the file DATA.TXT contain the following data: n, o, p, q, r, s, t.
(A) rst
(B) pon
(C) nop
(D) qpon
What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim num as Double, sum As Double = 0
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
Do While sr.Peek <> -1
num = CDbl(sr.ReadLine)
sum += num
Loop
sr.Close()
txtBox.Text = CStr(sum)
End Sub
The three lines of the file contain the following data: 2, 9, 32.
(A) 12
(B) 43
(C) a run-time error
(D) 0
What is wrong with the following program that intends to calculate the average of student test scores? Assume that the file DATA.TXT has several numeric entries.
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim total, score, average, numItems As Double
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
total = 0
numItems = 0
score = CDbl(sr.ReadLine)
Do While sr.Peek <> -1
total += score
numItems += 1
score = CDbl(sr.ReadLine)
Loop
sr.Close()
average = total / numItems
txtBox.Text = CStr(average)
End Sub
(A) The variable score is not initialized.
(B) The accumulator does not add the last score in the file.
(C) A division by zero error could occur when computing the average.
(D) There is nothing wrong with the program.
What is wrong with the following simple password program where today's password is "intrepid"?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim password As String
password = InputBox("Enter today's password:")
Do
lstBox.Items.Add("Incorrect")
password = InputBox("Enter today's password:")
Loop Until password = "intrepid"
lstBox.Items.Add("Password Correct. You may continue.")
End Sub
(A) There is no way to re-enter a failed password.
(B) The Loop Until condition should be passWord <> "intrepid".
(C) It will display "Incorrect." even if the first response is "intrepid".
(D) Nothing
How many times will HI be displayed when the following lines are executed?
Dim c As Integer = 12
Do
lstBox.Items.Add("HI")
c += 3
Loop Until (c > 27)
What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim vowel As String
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
Do While sr.Peek <> -1
vowel = sr.ReadLine
txtBox.Text &= vowel & ", "
Loop
sr.Close()
txtBox.Text &= "and sometimes y"
End Sub
Assume the five lines of the file DATA.TXT contain the following data: a, e, i, o, u.
(A) and sometimes y
(B) a, and sometimes y
(C) a, e, i, o, u, and sometimes y
(D) a, e, i, o, u,
C
What will be displayed by the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim x, y, z As Double
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
y = 0
x = CDbl(sr.ReadLine)
Do While x < 5
If x = 4 Then
sr.Close()
sr = IO.File.OpenText("DATA.TXT")
End If
z = x + y
x = CDbl(sr.ReadLine)
y = CDbl(sr.ReadLine)
Loop
txtBox.Text = CStr(z)
sr.Close()
End Sub
The nine lines of the file DATA.TXT contain the following data: 3, 4, 6, 8, 1, 2, 5, 9, 3.
(A) 9
(B) 14
(C) 10
(D) 7
(E) None of the above
What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim letter As String
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
Do While sr.Peek <> -1
letter = sr.ReadLine
txtBox.Text &= letter
Do While (sr.Peek <> -1) And (letter <> "*")
letter = sr.ReadLine
Loop
Loop
End Sub
Assume the 12 lines of the file DATA.TXT contain the following data: a, b, c, *, d, *, e, f, g, h, *, i.
(A) abcdefghi
(B) abc*d*efgh*i
(C) adei
(D) a
What will be displayed by the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim j, k As Double
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
j = CDbl(sr.ReadLine)
Do While (j < 5)
k = CDbl(sr.ReadLine)
If k < j Then
j= CDbl(sr.ReadLine)
End If
Loop
txtBox.Text = CStr(k)
End Sub
Assume the six lines of the file DATA.TXT contain the following entries: 3, 4, 1, 5, 2, 6.
(A) 1
(B) 2
(C) 3
(D) 4
(E) 5
Given the following partial program, how many times will the statement lstBox.Items.Add(j + k + m) be executed?
For j As Integer = 1 To 4
For k As Integer = 1 To 3
For m As Integer = 2 To 10 Step 3
lstBox.Items.Add(j + k + m)
Next
Next
Next
(A) 24
(B) 60
(C) 36
(D) 10
(E) None of the above
What will be the output of the following program when the button is clicked?
Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
Dim letter As String
Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")
Do While sr.Peek <> -1
letter = sr.ReadLine
txtBox.Text &= letter
Do While (sr.Peek <> -1) or (letter <> "*")
letter = sr.ReadLine
Loop
Loop
End Sub
Assume the 12 lines of the file DATA.TXT contain the following data: a, b, c, *, d, *, e, f, g, h, *, i.
(A) abcdefghi
(B) abc*d*efgh*i
(C) adei
(D) a
(E) Infinite loop
Explanation / Answer
post the remaing bits clearly sure i ll help u
1 D
2 A
3 A
4 B
5 D
6 C
7 C
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.