English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i have this section of code:

Do While f < p
If c > b Then
f = f + 1
Form1.txtTime.Text = f
k = d * a
m = Math.Floor(c / b)
e2 = m + a
Form1.txtShares.Text = e2
g = (c - (b * m)) + k
Form1.txtMoney.Text = g
Else
f = f + 1
Form1.txtTime.Text = f
k = d * a
j = c + k
Form1.txtMoney.Text = j
End If
Loop

and it won't loop properly. the first condition in the if then else statement is usually false so it goes on to the else part, but when the loop is concerned it stays in the else part of the code, i need a way to make the loop statement go over the entire if then statement for the duration of the loop rather than just looping through the else statement

2007-06-26 19:01:41 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

also for...next doesn't work and do...loop while doesn't help either

2007-06-26 19:02:18 · update #1

i can get this section of code to work beautifully without the loop in there, so i know the if...then statement is fully functional. What happens is when it starts the loop sequence it notices that c

2007-06-27 04:34:42 · update #2

actually c and b do have values as well as p its just not in this section of code

2007-06-27 04:37:18 · update #3

4 answers

"i need a way to make the loop statement go over the entire if then statement for the duration of the loop rather than just looping through the else statement"

are you sure it satisfies the condition of the if statement?
as long as f is not less than p then it will always loop into the else statement

2007-06-26 19:12:04 · answer #1 · answered by abd 5 · 0 0

I do not see any code which assigns values to either C or B

The default values for unassigned variables are zero
so both C & B are equal to zero
The If condition C>B would then be 0>0 (is zero greater than zero) resulting in false and triggering the else portion of the code.

During the loop there is no code which modifies the value of either C or B so this condition will always be false.

You will need to add code which assigns updated values to C and/or B so that the evaluation of C>B has a chance of becomming true rather than being always stuck as false as it is now

2007-06-27 01:19:27 · answer #2 · answered by MarkG 7 · 0 0

What do you mean by "go over the entire if then statement"? I'm sure it does check the if condition, the thing is that "c>b" is an invariant here, meaning it stays true (or false) for the entire loop sequence. So this section of code is equivalent to this one:
If c > b Then
Do While f < p
...
Loop
Else
Do While f < p
...
Loop
End If

Hope this helps.

2007-06-26 21:36:03 · answer #3 · answered by DimaS 2 · 0 0

looks ok strange it wont

2007-06-26 19:04:41 · answer #4 · answered by Anonymous · 0 1

fedest.com, questions and answers