if-statement

Writing equality tests in an if statement

I wanted to see if someone could shed some light on this for me. When I was using the Checkstyle plugin for Eclipse, I got a warning message on the following statement (not exactly this, but this form): if (x != y) { do(); } Why is this a problem? Edit: I apologize, I should have been more clear with my question. Thanks very muc...

function functionName(if clause here) possible?

function getTemplate($tpl if ($vars) echo ", $vars";)...function Is this possible somehow? The above wont work. Thanks ...

numericUpDown problem...

Hi, I want to hide some things when the value of the numericUpDown is changed so I wrote this: if (numericUpDown1.Value = 1) { Label1.Hide(); } but I get this error message: Cannot implicitly convert type 'decimal' to 'bool' Thanks ...

PHP If else statement that a database record is empty it will display a default picture.

Hi basicly I am trying to create a simple IF statement that shows a default picture if one hasn't been entered in to my database. I am using server to store my picture and a database to store the file name, so I can get the image to display if it has a file name in the db but I want the If statement to say if the record is empty display ...

Evaluation of an IF statement in VB.NET

For the following If-statements in VB.NET, what will be the sequence in which the conditions will be evaluated? Case 1: If ( condition1 AND condition2 AND condition3 ) . . End If Case 2: If ( condition1 OR condition2 OR condition3 ) . . End If Case 3: If ( condition1 OR condition2 AND condition3 OR condition4) . . End If ...

Is it more efficient to branch or multiply?

I am trying to optimize a small, highly used function which uses the high bits in an unsigned short int to indicate the values of an array to sum together. At first I was using the obvious approach shown below. Please note that loop unrolling is not explicitly shown as it should be done by the compiler. int total = 0; for(unsigned short...

PHP File Validation using If statements uploads.

Hi I am quite new to php but i have been following some tutorials but they don't seem to work so I have tried to adapt them. I have tested this code and it works to a point but theres something else I can't get my head around, the php file is not uploading (fine) but the details are still being writen to the datbase although the $ok is...

How can Polymorphism replace an if-else statement inside of a loop?

How can polymorphism replace an if-else statement or Switch inside of a loop? In particular can it always replace an if-else? Most of the if-thens I use inside of loops are arithmetic comparisons. This question is spawned from this question. int x; int y; int z; while (x > y) { if (x < z) { x = z; } } How woul...

?: Operator Vs. If Statement Performance

I've been trying to optimize my code to make it a little more concise and readable and was hoping I wasn't causing poorer performance from doing it. I think my changes might have slowed down my application, but it might just be in my head. Is there any performance difference between: Command.Parameters["@EMAIL"].Value = email ?? Strin...

What is wrong with my `if` statement?

I'm using an if statement to declare whether a user is an admin, mod or neither with this code below, but its messing up by always making $status = "admin" even if that person is neither, this has really baffled me. if($info['rights'] == "m") { $status = '<font color="#FFFFFF">(mod)</font>'; }elseif ($info['rights'] == "a"); { $...

How do you get a #if conditional to work when unit testing?

this is what I would like to be able to do. /// <summary> /// Gets the session factory. /// </summary> /// <value>The session factory.</value> public ISessionFactory SessionFactory { get { if (_sessionFactory == null) { #if(NUNIT) ...

if question

hi , i have little problem with if { string nom; string ou; nom = "1"; if (nom == "1") { nom +=1; ou = nom; } Console.Write(ou); } but i cant print ou value i dont know why ...

C#: How can I combine a switch with an if-statement?

I need to combine a switch with an if-statement. How can I do that? I want to do something like this: switch (periodtype) { if(starttime>endtime) { ; } else { case 0: nextRunTime = nextRunTime.AddHours(period); break; case 1: nextRunTime = nextRunTime.AddMinutes(period); break; case 2...

if/else and if/elseif

If I have a statement block like this: if (/*condition here*/){ } else{ } or like this: if (/*condition here*/) else if (/*condition here*/) {} else if (/*condition here*/) {} What is the difference? It seems that with if/else, if part is for true state and the else part is for all other possible options (false). An else-if would...

Java - If statement with String comparison fails

I really don't know why the if statement below is not executing: if (s == "/quit") { System.out.println("quitted"); } Below is the whole class. It is probably a really stupid logic problem but I have been pulling my hair out over here not being able to figure this out. Thanks for looking :) class TextParser extends Thread { ...

PHP - Best practices evaluating IF statement

Consider the following if(!count($_POST)) { echo 'something'; } if(empty($_POST)) { echo 'something'; } if(!$_POST) { echo 'something'; } Each line above pretty much do the same thing. I haven't been particular about which one I use. Should I be more particular? Does it really matter? ...

How can I compare two files in a batch file?

Hello everyone! I recently found this site and thought I might try it out because it seemed very unique. How can I compare two files in a batch file, and perform an action based on whether or not they match? I've tried something like: if file1.txt NEQ file2.txt goto label but it compares the actual string "file1.txt" rather than the ...

What is the difference between IF-ELSE and SWITCH?

Can someone please explain this to me? ...

VB.Net: test multiple values for equality?

How do you test multiple values for equality in one line? Basically I want to do if (val1 == val2 == val3 == ... valN) but in VB.Net. ...

as3/javascript if statement> commas instead of &&

This runs in as3, and javascript. Why? I know how && and || work, but a list? is this as3 specific? Is this in other languages? I'm a mouth breathing PHP/AS2 programmer. Or did everyone already know this and I'm a tool for not reading documentation properly? AS3 if (true, true, true) { trace("true?") }//result - "true?" traced...