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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

MathCAD unexpectedly Exiting Nested For Loop

justhumm
5-Regular Member

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

1 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

justhumm
5-Regular Member
(To:LucMeekes)

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

Top Tags