I have the following exercise to complete...
1. Write a visual basic Do clause that processes the loop instructions as long as the value in the intQuantity variable is greater than the number 0. Use the while keyword.
Dim intQuantity AsInteger
Do
LoopWhile intQuantity > 0
2. Rewrite the Do clause from Exercise 1 using the Until keyword.
Dim intQuantity AsInteger
DoUntil intQuantity <= 0
Loop
3. Write a visual basic Do clause that stops the loop when the value in the intInStock variable is less than or equal to the value in the intReorder variable. Use the Until keyword.
Dim intInStock AsInteger
Dim intReorder AsInteger
DoUntil intInStock <= intReorder
Loop
4. Rewrite the Do clause from Exercise 3 using the While keyword
Dim intInStock AsInteger
Dim intReorder AsInteger
While intInStock > intReorder
EndWhile
5. What will the following code display in message boxes?
Dim IntX As Integer
Do While intX 5
Code seems truncated
7. Write the visual basic code for a pretest loop that uses an Integer variable named intEvenNum to display the even integers from 2 through 10 in the lblNumbers control. Use the For…Next statement. Display each number on a separate line in the control.
Dim intEvenNum AsInteger
lblNumbers.Text = ""
For intEvenNum = 2 To 10 Step 2
lblNumbers.Text = lblNumbers.Text & vbCrLf & intEvenNum
Next intEvenNum
8. Rewrite the pretest loop from Exercise 15 using the Do…Loop statement.
Dim intEvenNum AsInteger = 2
lblNumbers.Text = ""
Do
lblNumbers.Text = lblNumbers.Text & vbCrLf & intEvenNum
intEvenNum = intEvenNum + 2
LoopWhile intEvenNum <= 10
9. An instruction Is missing from the following code. What is the missing instruction and where does it belong in the code?
Dim intNumber As Integer = 1
Do While intNumber < 5
MessageBox.Show(intNumber.To String)
Loop
Answer:Following statement is missing: intNumber = intNumber + 1
It should come before loop ends to ensure definite loop
Dim intNumber AsInteger = 1
DoWhile intNumber < 5
MessageBox.Show(intNumber.ToString)
intNumber = intNumber + 1
Loop
10. An instruction is missing from the following code. What is the missing instruction and where does it belong in the code?
Do intNumber A s Integer = 10
Do
MessageBox.Show(intNumber.ToString)
Loop Until intNumber = 0
Answer:Following statement is missing: intNumber = intNumber – 1It should come before loop ends to ensure definite loop
Dim intNumber AsInteger = 10
Do
MessageBox.Show(intNumber.ToString)
intNumber = intNumber - 1
LoopUntil intNumber = 0
11. What will the following code display?
Dim intTotal As Integer
Do While intTotal <= 5
MessageBox.Show(inTotal.ToString)
intTotal = intTotal + 2
Loop
It would display 3 message boxes in a row. First would display 0, second would display 2 and third would display 4.