Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make an 'if' statement do "nothing"?

Here is an example of my code. I need the last if to do nothing, else do something.

if (daPilot.Gas > 0)
    ;
else
    daPilot.failMessage3();
like image 579
missahippy Avatar asked Oct 08 '14 18:10

missahippy


People also ask

How do you make nothing happen in an if statement?

Answer: use _ = 0 . I came up with the following code example which is valid in .

How do you say else do nothing in C?

If you want your last else to do nothing, you can use the continue keyword inside it. For any conditional you can define the conditional to do nothing by defining an empty code block {} for it or by simply ommit the case.

What if there is no condition in if statement?

A condition need not necessarily contain comparators such as == or < etc. A condition can be any expression. Now, if the if expression evaluates to a zero value it is considered false and the if statement is not evaluated. Otherwise, it is considered true and the if statement is evaluated.


1 Answers

You've already done it. Congratulations.

Of course the far less confusing design is to just NOT the condition and then have an if with no else.

like image 51
Servy Avatar answered Oct 04 '22 09:10

Servy