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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Exiting out of For Loops

Heavenly
1-Newbie

Exiting out of For Loops

In the attached Mathcad 15 document I have a for loop that defines certain cases. In this example the equality is satisfied for case 5 and case 6 but the loop is returning the last equality that is satisfied and I need to have it start the loop at case 1 and exit the loop after the first equality is satisfied. Any help is greatly appreciated. Thanks.

6 REPLIES 6
LucMeekes
23-Emerald III
(To:Heavenly)

See if it helps to add a break in the if statements, like this:

Success!

Luc

Luc,

How do I define an if statement without a variable definition in front of it?

Dave

LucMeekes
23-Emerald III
(To:Heavenly)

Use the if function?

if ( {condition} , {statement if true} , {statement if false} )

Or is it that you wonder how the constructions I showed above are made...?

Put your cursor on the statement / placeholder in front of the if

  and add a program line, either from the menu or using the "]" key.

Success!
Luc

We can use return instead break

You can't use return, as Valery suggested, as this will end the whole calculation and you won't get the vector you need.

Using break seems to cancel the for-loop completely

So I guess its "continue" which you have to use.

Another option would be to nest the if's using "otherwise".

The way you described your problem in your question could be interpreted as if you just one one single value to be returned - cancelling the whole routine after the first match weas found. If thats the case,  "break" and "return" should do the job and I would favor using return.

But in your sheet you create a vector of values, so I assumed that this is what you are after.

R

MJG
18-Opal
18-Opal
(To:Werner_E)

You can use "return" if you remove the loop from the program and set up the problem a little differently:

Top Tags