ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement if then else?

Hey Friends,

if i want to make a program (if the input is x and L).

if the x is less than -L output must be 0

if the x is between -L and 0 output must be 1

if the x is between 0 and L output must be 2

if the x is more than L output must be 3.

What should be done(since there isnt any if then else commnad in labview)?

 

Thanks in advance

 

Regards

0 Kudos
Message 1 of 16
(14,554 Views)

@interstellar wrote:

(since there isnt any if then else commnad in labview)?


The "else" in LabVIEW is the false case

 

IF x Then (do the True case) else (do the False case)

Just like you nest IF ELSE statements in text based, you also nest True/False cases in LabVIEW

Omar
0 Kudos
Message 2 of 16
(14,543 Views)

Thanks..  is there any other way?

0 Kudos
Message 3 of 16
(14,536 Views)

The case selector will accept a number.  You can also have ranges for a case (e.g.    0..5 is zero to five).

 

Check the help on case structures.

 

https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/structures/case-structure.html

 

http://digital.ni.com/public.nsf/websearch/A5D77ADCA661670386256A480062A340?OpenDocument 

 

 

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 4 of 16
(14,529 Views)

ElseThen.png

Omar
0 Kudos
Message 5 of 16
(14,523 Views)

Your first and fourth rules are both true in this case, but this is a convenient way to test multiple criterion.

 

ifthenelse.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 6 of 16
(14,519 Views)

I know you can do this with a formula node.  Not sure how performance compares to other methods.

0 Kudos
Message 7 of 16
(14,482 Views)

Thanks for your reply.. 

cant the range be variable.. like for this case L?

0 Kudos
Message 8 of 16
(14,459 Views)

DON'T DO THIS!!!!  There's a note in a style guide, somewhere, that says something ugly about nesting too many Case Structures.  It's tempting, though, and more analagous to If-Then-Else than my first response.

ifthenelse_BD.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 9 of 16
(14,457 Views)

I did this initially but this did not look nice and was difficult to understand..

 

What if i want to use case structure. like what vt92 said

The case selector will accept a number.  You can also have ranges for a case (e.g.    0..5 is zero to five).

 

Check the help on case structures.

 

https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/structures/case-structure.html

 

http://digital.ni.com/public.nsf/websearch/A5D77ADCA661670386256A480062A340?OpenDocument 

 

cant in place of number a variable be used? like in my example 'L'...

0 Kudos
Message 10 of 16
(14,445 Views)