cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Loop problem

Ermis76
1-Newbie

Loop problem

Hi!

I have a question regarding the iteration in the attached.

Further down the sheet in the body of the iteration/loop i have a statement that if the condition in "step18a (f.x1,f.x)=1" then the iterationprocess will continue to step19 and so on. If not, then value of step18b (f.x1,f.x) will be returned to "v" this is the angle.

Now i would like the value calculated in the function step18b (f.x1,f.x) to be returned to the intial "v" located in the second body way up at the begining of the calculation. I suspect that this is not occurring at present. I have tried with the continue statement at the end but i think that is not the right way to go about it.

Does anybody have any suggestions how to solve this?

Thanks in advance!

4 REPLIES 4
RichardJ
19-Tanzanite
(To:Ermis76)

Do you mean the "v" in the outer loop? That might or might not get updated with the v from step18b. It will happen only if the condition for the inner loop fails, and the calculations therefore exit that loop. Since you have return statements in the inner loop, that may never happen because the program may exit first. You can check if it ever happens by changing your trace statement (which is in the outer loop) to show v. You will get one value for every time the outer loop executes. The value does change at one point, so it's getting a new value for v from somewhere

The continue statement causes subsequent calculations in the loop to be skipped (for example STEP10a), so unless that's what you want, get rid of them.

Thanks Richard!

Yes i meant the "v" in the outer loop. You are correct that the value of v changes at one point and it seems that it comes from step 18b in the inner loop.

Shouldnt the angle "v" keep changing as long as the value in step 18a is zero?

Then while the angle changes the value of step17b should change which would meet the condition in step18a in the inner loop.

Thanks again , i've been stuck with this problem now for quite some time

RichardJ
19-Tanzanite
(To:Ermis76)

You need to use the trace statement to literally trace backwards through the calculations. If v is only changing one then fx1 is only changing once (because fx appears to be fixed). Since fx1 is set by step 17b, either fcx or fsx (or possibly both, although that's unlikely) is only changing once (the other probably does not change at all). And so on.

You would find it easier to debug this if you broke it down into smaller functions. For example, take the entire if block involving step 18a, and turn it into a function. Test the function for various input values so you know it does what you expect it to do. Once you have that working, do the same for step 14. The more you can break it down into sub-functions that can be independently tested the easier it will be to find mistakes (either in the programming, or you logic).

Thanks for the tip i'll try that!

Top Tags