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

Nested if Statements

SOLVED
Highlighted
Newbie

Nested if Statements

I need to do some nested if statements for conditional programming and I cannot figure out for the life of me how to nest if-statements using the programming toolbar. I am in Matcad 14 and the "add line" button just adds if-else if statements, I need to nest. All the "add line" option does is just add another line on the same logic level. Is there a difference between if and conditional if?

I posted a flowchart of the basic program logic. (Ignore the red lines, that is just my spell checker)

flowchart.png

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Nested if Statements

When you enter the if there are two placeholders, one before the if (where the statement to be executed goes) and one after the if (where the condition goes). The cursor should be on the on before the if, but if it isn't then select that placeholder. Add a line using the programming toolbar, and the structure of the if statement will change so that you have a block of statements below the if. Now you can add another if as one of those statements. As long as you always have more then one line in the statement block the structure of the nested if is clear. It's not actually necessary to have more than one line, but the structure is impossible to figure out if you don't (as you have discovered!).

View solution in original post

17 REPLIES 17

Re: Nested if Statements

It's very hard to figure out the structure of nested if statements if they only have one line in the statement block. After adding an if, add a second line to the block. Then add the next if, and so on.

Re: Nested if Statements

So I can't do something like this?

nestedif.png

I found this through google in a Mathcad primer PDF. The problem is I physically can't figure out how the keystokes to get just "if .......". The only if statement I can find is through the programming logic which is "......... if .............", and even then I can't figure out how to nest them. Thanks.

Re: Nested if Statements

When you enter the if there are two placeholders, one before the if (where the statement to be executed goes) and one after the if (where the condition goes). The cursor should be on the on before the if, but if it isn't then select that placeholder. Add a line using the programming toolbar, and the structure of the if statement will change so that you have a block of statements below the if. Now you can add another if as one of those statements. As long as you always have more then one line in the statement block the structure of the nested if is clear. It's not actually necessary to have more than one line, but the structure is impossible to figure out if you don't (as you have discovered!).

View solution in original post

Re: Nested if Statements

Thanks! I'll mess around with it but it was the keystrokes that were getting me not the program logic!

EDIT: Got it working, I posted a screen shot if anyone else runs into a similar problem. To add extra lines click on the box before the if statement and the otherwise statement. The black lines act like brackets in text based programming

nestedif.png

Message was edited by: Brad Trammell (mathcad file with solution)

Re: Nested if Statements

That function could be cleaned up a lot.

Can you post the worksheet?

Mike

Re: Nested if Statements

Sure, ignore the other stuff around it. I can't imagine the way I did it is the best but it is functional for the time being.

Re: Nested if Statements

One observation: the program does not cover the case for Cr=0.01

Re: Nested if Statements

does the last line not get read by the program?

1-exp(-NTUtotal) if Cr < 0.01

should I change that to an otherwise?

Re: Nested if Statements

Sure, ignore the other stuff around it. I can't imagine the way I did it is the best but it is functional for the time being.

There seems to be something fundamentally wrong with your function.

  • What happens if Cr is 0.01?

The function falls over.

Mike

Announcements