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

SOLVED
Participant

## How to drop out of loop

Here is my FORTRAN statements:

DO 1010 I=1,L

DO 1010 J=1,NC119

X119(I,J) = 0.

X132(J,I) = 0.

IF(YEN(J) -YV(I)) 1010,1000,1000

1000       X119(I,J) = 1.0

1010 CONTINUE

JAK = 1

DO 1040 I=1,NC119

DO 1020 J=JAK,L

IF(YE(J)) 1020,1020,1030

1020   CONTINUE

GO TO 1040

1030   X132(I,J) = 1.0

JAK = J+1

1040 CONTINUE

I include my attempt, results and what I want.

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

## Re: How to drop out of loop

Are you looking for this?

Success!
Luc

16 REPLIES 16
Highlighted

## Re: How to drop out of loop

Your Prime  and Fortran programs are different.

Assuming the Fortran code functions according to your desired behaviour (whatever that may be), these are the differences I see so far:

JAK <- JAK+1 should be JAK<J+1

You to place this JAK assigment immediately below the X132 assignment, not below/outside of thye entire IF statement.

Success!
Luc

Highlighted

## Re: How to drop out of loop

X132i,j  1
JAK  j + 1
gives me a 1x12 matrix, not a 2x16.
Ken
Tags (1)
Highlighted

## Re: How to drop out of loop

The "IF(YE(J))" in your Fortran code looks like an IF statement at first sight, but it isn't because it is NOT followd by "THEN".

What does it do? Especially the three numbers following the IF() are puzzling. Are they line numbers? And how are they processed?

In the first Mathcad program (X119) you translated the IF(argument) with "if argument >=0" in X132 you translated a similar construct IF(argument) with 'if argument <=0". Which one of the two is right, 'less than or equal', or 'larger than or equal' ?

It might help a lot if you could explain what functionality you wanted to program. What is the effect that your function should accomplish, in plain text.

Success!
Luc

Highlighted

## Re: How to drop out of loop

That "IF(YE(J))" in the Fortran code IS an IF statement, unless you are using some version I am not aware of. "IF...THEN..." sounds like  BASIC code too me. To me "IF(YE(J)) 1020,1020,1030" in FORTRAN means "IF(YE(J)) ≤ 0 go to statement 1020,or > 0 go to statement 1030". I work in FORTRAN versions like WATFOR or 95, which might be before your time and any newer International Standards.

If you were able to examine my MathCad Prime 3.1 attachment, I listed the known variables and attempts for the 2x16 row matrix called X132. I just cannot get a single "1" in the desired elements, i.e. 1,1 and 2,12. The 16x2 column matrix X119 is correct.

Highlighted

## Re: How to drop out of loop

Are you looking for this?

Success!
Luc

Highlighted

## Re: How to drop out of loop

Got it! See attachment.

Highlighted

## Re: How to drop out of loop

Most interesting approach, I was not aware that any version of MathCad (including Prime) had these functions.

Thanks for you assistance. Hope you were able to view my previous attachment.

Ken

Highlighted

## Re: How to drop out of loop

LucMeeks,

Here is my final attempt. I have tried reducing statements, but I cannot. Your solution seems to want an exact match(?) between YEN and YV.

Ken

Tags (2)
Highlighted

## Re: How to drop out of loop

Here is my attempt to translate your FORTRAN program to Prime one to one. Its similar to yours and the missing point, as you had found out on your own, was the break command to jump out from the inner loop (which nowadays is considered bad programming style ;-).

Of course this can be made a bit shorter because in Mathcad, as you found out yourself, its not necessary to set every single element in a matrix to zero. The values are zero by default, no need to initialize.

Not sure if you already realized, that variables used in a Prime program at the left side of an assignment are always local variables only and do not correspond to variables at worksheet level with the same name. So your second program does NOT use the X132 you created in your first program. The only way to change worksheet variables is to assign them the result of a program. So you may notice that the program variables in my program are called X119 and X132 but the worksheet variables have different names (same, but with the number as literal index).

Luc's suggestion only works in MC11, not in MC15 and also not in Prime.

Here is a similar approach which works in Prime, too. It uses Y.E for comparison as the original program:

As I could only provide a Prime 5 or Prime 6 worksheet, I don't attach it as your Prime 3.1 would not be able to read it.

Announcements