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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

While loop not working correctly.

ptc-6721944
1-Newbie

While loop not working correctly.

Hi all.

I am trying to write a program that will increment a value of x by a predetermined amount, run through a few equations, and then re-evaluate that condition. If that condition is not met, return the value of x to H_loop.

I have attached the program, "loophelp". You will have to change the line in the program "H_loop" from "STDD > STDD_allow" to "STDD < STDD_allow" for it to run.

I wrote a program that was very similar in structure to the right of the program I am having trouble getting to work. I am not understanding why that one runs with no issue, but the one on the left will sit and spin its wheels ad infintium.

Thanks for any help.

-JW

1 ACCEPTED SOLUTION

Accepted Solutions

Not sure what you want to achieve with your while-loop.

The only statement in your loop is the incrementation of x which does not change the value STDD at all. So either your loop will not run at all or it will run endless.

If you want the value of STDD being calculated in the loop, you have to put the calculation of STDD inside the loop and not before it.

View solution in original post

3 REPLIES 3

Not sure what you want to achieve with your while-loop.

The only statement in your loop is the incrementation of x which does not change the value STDD at all. So either your loop will not run at all or it will run endless.

If you want the value of STDD being calculated in the loop, you have to put the calculation of STDD inside the loop and not before it.

One additional remark: Even if you put your calculations inside the loop it will run endless.

The reason is that for the initial value of x=0.984 (HG_calc) STDD already is 3952.1 which is smaller than the reference value of STDD_allow. When you increase x, STDD becomes even smaller as STDD converges against zero for increasing x. This means even when you set up correct you will have an endless loop.

If you just want to know which value of x makes STDD = STDD_allow, just turn the calculation of STDD into a function and solve the appropriate equation either using a solve block or using the root command.

If you insist to use your routine, you will have to change the last but one line from x+0.0625 to x-0.0625. Then, and if you put the calculations inside the loop, you get x=0.421. This is far away from the correct value of x=0.49173 because of the rather large stepwidth (0.0625).

1.png

Thank you so very much for your help Werner. I have got it to work.

Have a great day.

-jw

Top Tags