Jump to content

Simple if statement


Recommended Posts

I want to write a simple if-else statement in the Formula node in Labview.

I want to write

if (condition)

execute

else if (condition)

execute

else

execute

end

end

but the "else if" generates error in statement. Is this way of writing not allowed?

/grogg

edit: Sorry I guess I should have wrote in the General Section

Link to comment
Why don't you simply use a case structure to do what you want?

You may create as many cases (for each different condition) as you want, and do your calculations inside each different case.

5223[/snapback]

I have already five cases in a case structure and this if-else statement will just be in one of them. If it is possible to write "else if" i would be much easier than doing another case structure inside the first one. I very new at using labview, maybe there is an easier way.

Link to comment

Use a case structure with a numeric, enum, or string feeding the question mark terminal.

In LabVIEW, each of your "If" and "Else If" conditions will occupy one case of the case structure. You can also use ".." to handle a range of options, such as "0..3", which would work for values 0, 1, 2 or 3. The regular "Else" is equivalent to the case noted as "Default" in the LabVIEW case structures. This can be a case by itself, or it can be assigned to any other case, so you may want the default case to be the case for value 0, so it would look like "0, Default".

Link to comment

Ah... I just noted that you are using a formula node... somewhat different. Can you exit the formula node and use the regular LabVIEW case structure? It seems like you would be able to re-enter the same node or a slightly different one following execution to pick up where you left off.

Link to comment
Ah... I just noted that you are using a formula node... somewhat different.  Can you exit the formula node and use the regular LabVIEW case structure? It seems like you would be able to re-enter the same node or a slightly different one following execution to pick up where you left off.

5228[/snapback]

The code is somthing like this

if (mod(x,y)==0)

statement

else if (mod(x2,y2)==0)

statement

else

statement

end

end

If I would make a case structure, I would have to make the mod(x,y) outside the structure but I don't know how to do that. I guess I could use the block called formula.

Link to comment
Hmmm.  I use the quotient/remainder function (Block Diagram > Numeric > Quotion & Remainder) to check for even multiples.  Is that what you're trying to do?--or something different?

5230[/snapback]

Yes, that was what I wanted to do thanks. I think I can fix it now. I just not use to this way of programming. I think I prefer to writing simple if statements, but I guess I will get use to it :) .

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.