Skip to main content
10-Marble
January 10, 2024
Solved

MathCAD unexpectedly Exiting Nested For Loop

  • January 10, 2024
  • 1 reply
  • 1230 views

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

Best answer by LucMeekes

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

1 reply

LucMeekes23-Emerald IVAnswer
23-Emerald IV
January 10, 2024

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

justhumm10-MarbleAuthor
10-Marble
January 10, 2024

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