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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Translate the entire conversation x

Passing variables to nested While loops

KA_13455177
3-Newcomer

Passing variables to nested While loops

I have a question about variable definitions in programming. I have a program with two nested while loops. The second (nested) while loop balances forces in a structure. The first while loop updates a variable DeltaT until some additional criteria is met. DeltaT needs to update in the second (nested) while loop for the program to work. However, the updated value of DeltaT from the first loop is not being passed to the second loop. Why is this, and what can I do to fix the problem?

 

Program is on page 8 of attached spreadsheet. Check and Check 3 demonstrate that the variable is not updating in the nested loop.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:KA_13455177)

Your outer while-loop loops five time (y=0 til y=4) but the inner while-loop is only looped (23 times) in the first loop of the outer one (when y=0).

Because of the condition you have defined for the inner loop its not entered at all when y=1,2,3,4.

So Check and Check3 both are assigned the initial value of DeltaT (40) and these variables never are changed after that because the inner loop is never entered again. So Check2 which is assigned in the outer loop at the end holds the last but one value of DeltaT (2.852) and DeltaT is once again modified in the last run of the outer loop and gets the value 1.474.

So you may have to check why the condition in the inner while loop is not fulfilled after the first run of the outer loop.

 

BTW, you may get rid of variable "SlipCheck" and replace "while SlipCheck = 0" by "while y < 5".

View solution in original post

3 REPLIES 3
LucMeekes
23-Emerald IV
(To:KA_13455177)

You should state that you're using Prime 10.

 

To your problem:

Where, in the inner while loop, is an assignment to DeltaT ?

 

Side note: You should not evaluate a definition (put an '=' at the end of a definition).

Often it works, but ever so often it brings trouble.

Better is to evaluate the program using a separate evaluation:

 Program =

below the definition of Program.

 

Success!
Luc

Werner_E
25-Diamond I
(To:KA_13455177)

Your outer while-loop loops five time (y=0 til y=4) but the inner while-loop is only looped (23 times) in the first loop of the outer one (when y=0).

Because of the condition you have defined for the inner loop its not entered at all when y=1,2,3,4.

So Check and Check3 both are assigned the initial value of DeltaT (40) and these variables never are changed after that because the inner loop is never entered again. So Check2 which is assigned in the outer loop at the end holds the last but one value of DeltaT (2.852) and DeltaT is once again modified in the last run of the outer loop and gets the value 1.474.

So you may have to check why the condition in the inner while loop is not fulfilled after the first run of the outer loop.

 

BTW, you may get rid of variable "SlipCheck" and replace "while SlipCheck = 0" by "while y < 5".

Hi @KA_13455177,

 

I wanted to see if you got the help you needed.

If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.
Please note that industry experts also review the replies and may eventually accept one of them as solution on your behalf.
Of course, if you have more to share on your issue, please pursue the conversation.

 

Thanks,
Anurag 

Announcements


Top Tags