Do Loop Exercises Answers

1) For the following code
    a. How many numbers will be displayed?      21  (every integer starting with 1 and ending with 21)
    b. What will the first number printed be?        1
    c. What will be the last number displayed?   21

Dim intNum As Integer
 
intNum = 0
 
Do While intNum <= 20
        intNum += 1
        MsgBox(intNum)
Loop

 

2) What will be the output from the following?

Dim decBalance As Decimal
Dim
decAPR As Decimal
Dim
decTargetAmount As Decimal
Dim
intYears As Integer
 
decBalance = 1000
decAPR = .10
decTargetAmount = 1500
intYears = 0
 
Do
        decBalance = decBalance + (decBalance   * decAPR)
        intYears += 1
Loop Until decBalance >= decTargetAmount
 
Msgbox(“Balance = “ & decBalance & “ after “ & intYears)
 

     Output – Balance = 1610.51 after 5