if-statement

Simpler range finder?

Hay guys I've programmed a very simple range finder. The user can only select numbers 1 - 180 (axis) if the number is 90 or below i have to add 90 on to it if the number is 91 - 180 i have to take off 90 from it. Here's what i have $min_range = range(1,90); $max_range = range(91,180); if(in_array($axis, $min_range)){ $c = $axis...

JS: if statement issue, how to find element in body?

Hi, I am trying to write a simple if statement in javascript (jquery library) that simply finds the div.video element in the page and if it can find it set the variable 'arrows' to true, if it can't to false. Here is what I have so far: jQuery(document).ready(function () { // Hiding of prev & next arrows on movie pages. var arrows...

PHP if statement issue when checking for variable value

I'm trying to just write a simple PHP if statement that checks if a custom field has anything entered into or if it has been left blank. when it is blank it is meant to not print anything to the page, if something is set in the custom field then it should create a li element with an a tag inside of it. here is my code so far: <ul clas...

If Statement Hell, How to check if a date passed matches a date within 3 days but only if the date doesnt match the other conditions.

As the garbled question says I'm basically looking for a tidier way to do the following snip. (its used in a calendar for availability matching) //TODO: Optimize elseif Statement if (date.Year == now.Year && date.Month == now.Month && day == now.Day) { daysXhtml.Append("<td class=\"today\">" + day.ToS...

Recurrent if loop in a Switch

I would like to know if there is anyway I can do this without having to do the same If loop in each of the Switch cases since it's a bit repetitive. switch ($val) { case 1: if(!$object->doSomething1()==$goodValue) row .= $object->doSomething(); break; case 2: if(!$object->doSomething2()==$goodValue) row ...

Is it acceptable to only use the 'else' portion of an 'if-else' statement?

Sometimes, I feel like it is easier to check if all of the conditions are true, but then only handle the "other" situation. I guess I sometimes feel that it is easier to know that something is valid, and assume all other cases are not valid. For example, let's say that we only really care about when there is something wrong: object va...

How is if statement evaluated in c++?

Is if ( c ) the same as if ( c == 0 ) in C++? ...

How to run command using output of another command in DOS?

Example: for /? | if (this stream has word "the" in it) {echo the line with "the"} I need somehow to analyze the text in the redirected stream. ...

SQL IF ELSE BEGIN END

If there are no begin and end statements in sql, the next statement is the only one that gets executed if the if condition is true...in the case below, is there anyway the insert statement will also get executed if the if condition is true? IF (a > 1) SET @b = 1 + 2 INSERT INTO #F (a, b, c) VALUES (1, 2, 3) ...

How to check if a variable has any value from a given set?

How can I check if a condition passes multiple values Example: if(number == 1,2,3) I know that commas don't work. EDIT: Thanks! ...

C programming if statement

Hey guys, I know in C you can use do-while for single integers and characters but I was wondering if it is possible to use the same do-while feature for whole groups of numbers? EDIT: Okay i am really confused as to what this homework question is asking. But i think i get the question, just don't know what function will work. It wants...

Prioritize section of IF statement

I've got an IF statement that validates data. Basically looks like this: Dim s As String = Nothing If s Is Nothing Or s.Length = 0 Then Console.WriteLine("Please enter a value") End If Console.Read() I'd like to check to see if it's nothing first because if I write it this way, it throws a NullReferenceException. I've thought ...

Make an if statement shorter

Hay all, I have an if statement. How could I make this as short as possible? if ( $a < 0 ){ if( $a > -2 ){ echo "standard"; }elseif( $a <= -2 && $a > -4 ){ echo "thin"; }elseif( $a <= -4 ){ echo "super thin"; } }else{ if( $a < 2 ){ echo "standard"; } if( $a > 2.01 && $a <= 4){ echo "thin"; } ...

Objective-C can't use stringWithContentsOfURL data in IF statement

Hey, I'm trying to ping my server and check the version of the app - all goes well so far: NSURL *url = [NSURL URLWithString:@"http://thetalkingcloud.com/static/ping_desktop_app.php?v=1.1"]; NSError *theNetworkError; NSString *content = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&theNetworkError]; ...

Why is the 'if' statement considered evil?

I just came from Simple Design and Testing Conference. In one of the session we were talking about evil keywords in programming languages. Corey Haines, who proposed the subject, was convinced that if statement is absolute evil. His alternative was to create functions with predicates. Can you please explain to me why if is evil. I u...

mysql if condition

in my query i have IF(friend.block, 'yes', 'no') and friend.block value is 0 or 1.. but eaither way its putting 'yes'.. any idea? ...

Understanding the "||" OR operator in If conditionals in Ruby

Just briefly, why are the following three lines not identical in their impact? if @controller.controller_name == "projects" || @controller.controller_name == "parts" if @controller.controller_name == ("projects" || "parts") if @controller.controller_name == "projects" || "parts" The first gives me the result I want, but as there's a...

OCaml - For Loop inside If Statement

Coming from a Java and C background, grasping some concepts of Ocaml has been quite interesting. One such is, getting a/multiple statement to run inside a for loop. let test_method (x:vector list)(vec:vector) = if List.length x != 0 then {a=0.;b=0.} (* Return a vector of 0,0 *) else for i = 0 to List.l...

Excel Embeded If Statements

In excel is it bad to have about 1000 embedded if statements? I have about 1000 options that I want to pre-populate in other excel fields, what is the best way to do this other then inefficient if statements? ...

scheme and if condition

Hi I want to return nothing when if condition is not met, for instance (if x y z) so if x is not met, z will be executed and I want to do nothing at z, just same as pythons "pass" ...