if-statement

Order of operators in IF statement

I often do this when necessary to prevent a null pointer exception: // Example #1 if (cats != null && cats.Count > 0) { // Do something } In #1, I've always just assumed that the cats != null needs to be first, because order of operations evaluate from left to right. However, unlike example #1, now I want to do something if the obj...

What's wrong with my IF statement?

I'm creating an auditting table, and I have the easy Insert and Delete auditting methods done. I'm a bit stuck on the Update method - I need to be able to get the current values in the database, the new values in the query parameters, and compare the two so I can input the old values and changed values into a table in the database. Here...

In C# how can i use the || operand in an if state where im looking for 2 files?

I'm getting the error "Operator '||' cannot be applied to operands of type 'bool' and 'string'" when I use the below statement. if (File.Exists(@"C:\file1.exe") || (@"c:\file2.exe")) { do something } How can I do this? Thanks ...

Java Loop Efficiency. if-continue OR if

Hi. The question being thought today while completing my task is about the loop efficiency.. Lets say. I have an array {'a','x','a','a'} And a loop that should avoid 'x' element Now i wonder how these two approach differ in term of efficiency - not taking the while or do-while or for loops differentiation char[] arrExample = {'a','x'...

Javascript: This if statement should not detect 0; only null or empty strings

How do I NOT detect 0, but otherwise detect null or empty strings? ...

Jquery Menu remembering the state of the menu.

Hello, I am trying to get my menu system to read a cookie to it can remember the menu state. once remembered the menu would stayopen/close depending on the cookie. using alert in the javascript ive been able to read the cookie before and after clicks but sadly I cannot get the if statement correct in order to keep open/close the hidden...

Javascript IF execution error

The following is a part of my code : $.post("checkbuddy.php",function(data){ if(data!="a"){ $("#Layer15").css({ visibility: 'visible'}); $("#Layer10").css({ visibility: 'visible'}); $("#Layer10").html(data); } }); The condition if(data!="a") doesn't seem to be working, as checkbuddy.php returns "a". And what happens i...

Syntax of if exists in IBM Db2

The follow query drops a table if the table exists but it doesnt seem to work for IBM Db2. Begin atomic if( exists( SELECT 1 FROM SYSIBM.SYSTABLES WHERE NAME='EMAIL' AND TYPE='T' AND creator = 'schema1' )) then drop table EMAIL; end if; End Whereas the same if exisits syntax works if i have a DML st...

C# if statements matching multiple values

Any easier way to write this if statement? if (value==1 || value==2) For example... in SQL you can say where value in (1,2) instead of where value=1 or value=2. I'm looking for something that would work with any basic type... string, int, etc. ...

Javascript If Else nesting

Hello here is my code : var one = 0; var two = 0; var three = 0; var free = 1; function open() { if ($('#one').is(':visible')) { one = 1; } else { one = 0; free = 1; } if ($('#two').is(':visible')) { two = 1; } else { two = 0; if (one == 1) ...

&& and || in Scala

Hi, since normal operators like +, ::, -> and so on are all methods which can be overloaded and stuff I was wondering if || and && are methods as well. This could theoretically work if this were methods in of the boolean object. But if they are, why is something like if (foo == bar && buz == fol) possible? If the compiler reads from ...

using Boolean Object

i'm having issues trying to get the result I wish. Basically what I want to do is have a Boolean object which will allow me to have 3 choices, if a mailer is old i want it to be set to false (meaning does not contain "mapQ.cmd" and "add-coid.cmd" file) if a mailer is new I want it to set to true (if it is new it will contain "mapQ.cmd" ...

Boolean Table in VB.Net - Select Case, If-Else, or Something else?

Hey all, I'm looking to simplify the handling of a three-item Boolean expression. "Select Case" doesn't seem offer a solution for triple values, and the If statement seems a bit much. It'll work the way I coded it, but if you have any ideas on how to simplify this, I'd appreciate your insights. If not, I hope this snippet can save someon...

PHP if element exists, add width; if not, don't

I'm setting up a horizontally scrolling site, with Index Exhibit. One section needs to have a video, which I can't set up in the Indexhibit CMS backend (where it would add it to the wide div's width), so I need to add it to the PHP generation file. Basically, it needs to check if an element with the ID vid is present. If so, it should ad...

How to have condition checking (if command) when use refered parameter of the command line?

In my batch file I have the script: set myVar=/someLabel:"%1" I want to write the if command for the above script that have the same meaning as below. if <%1 not null> { myVar=/someLabel:"%1" } else { myVar="" } How can I do this? Please help! [Edit] The answer from user hfs works for me. The full details of the if and set ...

If block vs Switch-Case block

Generally is there a performance difference between using an if block with many else ifs compared to a switch case block? Do some languages or style conventions prefer one over the other? Specifically I am curious about Matlab, C, and C++ ...

Detect which button is pressed? (then action)

Hi guys! That's my very first post on SOF. I'm a new programmer at objective-c. Heres the "problem" i'm dealing with I created 2 UIbutton : one to pull an UIImageView from the top of the screen and the other to push it back. I have the code for the action** but i dont know how to relate it to an if-statement if(button1 pressed) then pu...

Calculate median for each subject with update on ties? [R]

I have data which looks like this (this is test data for illustration): test <- matrix(c(1, 1, 1, 2, 2, 2 , 529, 528, 528, 495, 525, 510,557, 535, 313,502,474, 487 ), nr=6, dimnames=list(c(1,2,3,4,5,6),c("subject", "rt1", "rt2"))) And I need to turn it into this: test2<-matrix(c(1,1,1,2,2,2,529,528,528,495,525,510,"slow","slow","fa...

c# is this design "Correct"?

I currently have the following if (!RunCommand(LogonAsAServiceCommand)) return; if (!ServicesRunningOrStart()) return; if (!ServicesStoppedOrHalt()) return; if (!BashCommand(CreateRuntimeBashCommand)) return; if (!ServicesStoppedOrHalt()) ...

Testing user input against a list in python

Hi, i need to test if the user input is the same as an element of a list, right now i'm doing this cars = ("red","yellow","blue") guess = str(input()) if guess == cars[1] or guess == cars[2]: print ("success!") But i'm working with bigger lists and my if statement is growing a lot with all those checks, is there a way to refe...