Discussion:
Simple elseif statement
(too old to reply)
groogg
2005-07-06 14:40:38 UTC
Permalink
I want to write a simple if-else statement in the Formula node in Labview.I want to writeif (condition)executeelse if (condition)executeelseexecuteendendbut the "else if" generates error in statement. Is this way of writing not allowed? Can I do it in another way?
I want to avoid using a case structure since I already have 5 cases in one case structure and this if statement is just going to be in one of these./grogg
Novatron
2005-07-06 14:40:40 UTC
Permalink
I thought that code in those nodes was based on C...  If my memory
serves me correctly, an else if statement is C is "elsif" not "else if"
groogg
2005-07-06 15:10:37 UTC
Permalink
Novatron wrote:I thought that code in those nodes was based on C...  If my memory serves me correctly, an else if statement is C is "elsif" not "else if"


I also thought it was base on C. I have tried elseiff too.
jhoskins
2005-07-06 14:40:39 UTC
Permalink
Here is the syntax that I found in the help on if statements. Try looking at the help. Sorry i could not help more
 

if-statement:

if ( assignment ) statement

if-else-statement:

if-statement else statement
groogg
2005-07-06 14:40:42 UTC
Permalink
I have look in the help. I'm sorry but it makes no sense writing
if statement else statement
did they forget to write (assignment). I thought it would be
if (assignment) else (assignment) statement
 
The help file does not say anything about the syntax for else if but I didn't think it would be a problem. Wrinting one if-statement inside another shouldn't be any diffrent then writing a while loop inside another while loop.
groogg
2005-07-06 17:10:38 UTC
Permalink
tbob wrote:
Forgive me for sounding arrogant or foolish, but don't we use Labview to get away from text coding?  Why even bother with if-else statements in a formula node?  Why not do the whole construct in Labview graphically?  I have never used a formula node and I don't expect to ever use one.  All formulas can be created with Labview numerical functions.  I guess I could see constructing a complex formula of math functions (X=2a^2+4b+c-d) using a formula node, but why would anyone want to use a formula node to perform text based coding like if-else and such?  Use Labview graphics and your troubles are over.

That answer was as helpful as when people ask for help with windows and the reply is use Linux. Sorry if I sounded arrogant.
groogg
2005-07-06 17:10:44 UTC
Permalink
The answer is very simple. The code should be:
 
if (condition) {
    statement
    }else{ if (condition){
                  statement
               }else{
                        statement
               }
 
    }

Loading...