I need help generating a VBA macro for the FOR statement below. Four different D
ID: 3604517 • Letter: I
Question
I need help generating a VBA macro for the FOR statement below. Four different DO LOOPS using four separate structures must be utilized:
The FOR statement below displays in a message box the numbers 1, 3, 5, 7, and 9. Write four different DO LOOPs, each using one of the four different structures (DO-While Loop, DO-Loop While, DO-Until Loop, and DO-Loop Until) to generate in a message box the same numbers 1, 3, 5, 7, and 9.
Dim x As Integer
For x = 1 To 10 Step 2
MsgBox x
Next
PLEASE PLEASE PLEASE use basic functions and statements -- nothing complex. Thanks so much!
Explanation / Answer
Do-While loop(check condition at beginning)
Function doWhile()
dim x as Integer
x=1
Do While x<10
msgbox x
x=x+2
Loop
End Function
Do-loop while (checks the condition at the end of loop)
Function doLoopWhile()
dim x as Integer
x=1
Do
msgbox x
x=x+2
Loop While x<10
End Function
Do-until loop (statements inside loop are executed only if condition is false)
Function doUntilLoop()
dim x as Integer
x=1
Do Until x>10
msgbox x
x=x+2
Loop
End Function
Do-loop until
Function doLoopUntil()
dim x as Integer
x=1
Do
msgbox x
x=x+2
Loop Until x>10
End Function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.