|
-
Sep 10th, 2006, 02:29 AM
#1
Thread Starter
Junior Member
looping problems??? (help)
How do I change both For...Next statements to Do...Loop statements.
'declare variables
Dim term As Integer
Dim principal, rate, payment As Double
Try
'assign input to a variable
principal = Double.Parse(Me.uiPrincipalTextBox.Text)
'display the years in the heading
Me.uiPaymentLabel.Text = " 3 yrs 4 yrs 5 yrs" _
& ControlChars.NewLine
'calculate and display the monthly payments, using
'rates of 5% to 10% and terms of 3 to 5 years
For rate = 0.05 To 0.1 Step 0.01
'display the current rate
Me.uiPaymentLabel.Text = Me.uiPaymentLabel.Text & rate.ToString("P0") _
& " "
For term = 3 To 5
payment = -Financial.Pmt(rate / 12, term * 12, principal)
Me.uiPaymentLabel.Text = Me.uiPaymentLabel.Text _
& payment.ToString("N2") & " "
Next term
Me.uiPaymentLabel.Text = Me.uiPaymentLabel.Text & ControlChars.NewLine
Next rate
Any Help would be greatly appreciated.
-
Sep 10th, 2006, 06:41 AM
#2
Re: looping problems??? (help)
Think about what you want to happen. A Do loop does something either While something is True or Until it is True. You can test that condition either before you Do something or after. You simply need to ask yourself these questions:
What do I want to Do?
Do I want to do it While something is True or Until something is True?
Do I need to test this condition before doing something or after?
I have to say, if you need to change a working For loop to a Do loop then this must be homework, so for us to just provide code is unethical. The fact that you're using "ui" as a prefix is more evidence of this because I've never seen anyone but students use that. Your user name kind of gives it away too. I suggest that you answer those questions for yourself and see where that leads you. Try writing some code and post back if it doesn't work.
-
Sep 10th, 2006, 07:20 AM
#3
Re: looping problems??? (help)
VB Code:
rate=0.05
Do Until rate>0.1
'display the current rate
Me.uiPaymentLabel.Text = Me.uiPaymentLabel.Text & rate.ToString("P0") & " "
term=3
Do Until term>5
payment = -Financial.Pmt(rate / 12, term * 12, principal)
Me.uiPaymentLabel.Text = Me.uiPaymentLabel.Text _
& payment.ToString("N2") & " "
term+=1
Loop
Me.uiPaymentLabel.Text = Me.uiPaymentLabel.Text & ControlChars.NewLine
rate+=0.01
Loop
And does it look bad when I use [Highlight=VB] tag?
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Sep 10th, 2006, 09:45 AM
#4
Fanatic Member
Re: looping problems??? (help)
Ugh, code tags suck man. It formats it so you can like read and everything. Dude they're a total waste of time.
As a side note he(/she?) also posted this in the classic VB forum and people have already given him the answer, myself included (hey it was 2:30AM, I wasn't thinking!).
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|