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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

MathCAD unexpectedly Exiting Nested For Loop

justhumm
10-Marble

MathCAD unexpectedly Exiting Nested For Loop

I have a Prime 7.0 worksheet with two matrices (of immediate interest). They are w [1x3] and P [3x2].

I am trying to manipulate and ensure that they have the same number of rows. And trying to do it with a nested loop.

 

BUT the inner loop seems to work once and then returns the matrix. The outer loop never increments to the next step.

 

I'm obviously doing something wrong, but can't see it.

If anyone could point me in the right direction, that would be great. Thanks!

 

FOR i: 1 TO rows(P)

---> FOR j: 1 TO rows(w)

---> ---> IF (criteria)

---> ---> ---> STACK (new row to w)

---> ---> ---> GOTO / SKIPTO next i

 

error.PNG

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:justhumm)

In your outermost for loop, the second assignment:

LucMeekes_0-1704893377858.png

changes P from a 3x2 matrix into a scalar.

That should lead to an error for the preceding assignment:

LucMeekes_1-1704893498590.png

when i is the next value (2) . For some reason it doesn't get there.

Ah, I see; the outer loop is only run for i=1 because your:

LucMeekes_2-1704893595677.png

is part of the outer For loop. Note that a return statement ends the program. You exit the program before you reach the end of the outer For loop.

 

Success!
Luc

View solution in original post

2 REPLIES 2
LucMeekes
23-Emerald III
(To:justhumm)

In your outermost for loop, the second assignment:

LucMeekes_0-1704893377858.png

changes P from a 3x2 matrix into a scalar.

That should lead to an error for the preceding assignment:

LucMeekes_1-1704893498590.png

when i is the next value (2) . For some reason it doesn't get there.

Ah, I see; the outer loop is only run for i=1 because your:

LucMeekes_2-1704893595677.png

is part of the outer For loop. Note that a return statement ends the program. You exit the program before you reach the end of the outer For loop.

 

Success!
Luc

The worksheet is still just a work in progress, but that solved that issue! 👍

Announcements

Top Tags