3
голосов
2ответов
4847 просмотров

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 *) ...

41
голосов
9ответов
71054 просмотров

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 gi...

3
голосов
3ответов
10174 просмотров

A MySQL IF condition

In my query I have an IF statement: IF(friend.block, 'yes', 'no') where friend.block value is 0 or 1.. but either way its putting 'yes'.. any idea?

69
голосов
18ответов
36945 просмотров

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...

1
голосов
4ответов
591 просмотров

Javascript if(function_foo()) doesn't wait for function_foo() to complete

I have an if statement: if(authenticate_session("secret_password12345")){ alert("You are authenticated"); }else{ alert("Intruder alert!"); } and the javascript authenticate function, which makes an jQuery POST AJAX call to the server to do the actual authentication,...

2
голосов
2ответов
6624 просмотров

Alternative conditional syntax (if-else) failing on PHP 5.3.0 (xampp)

I recently upgraded to xampp v1.7.2 which dumped PHP 5.3 on me. Along with that all my httpd.confs and php.ini's got wiped out (I had taken it for granted that this release will be an upgrade like all the earlier xampp releases). Anyway, it took me a while to reconfigure all the services - but no...

21
голосов
8ответов
53024 просмотров

How to assign a variable in an IF condition, and then return it?

def isBig(x): if x > 4: return 'apple' else: return 'orange' This works: if isBig(y): return isBig(y) This does NOT work: if fruit = isBig(y): return fruit Why doesn't the 2nd one work!? I want a 1-liner. Except, the 1st one will call the function TWICE. How to m...

1
голосов
2ответов
952 просмотров

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:NSASCII...

0
голосов
6ответов
290 просмотров

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 ...

0
голосов
2ответов
101 просмотров

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 throw...

0
голосов
5ответов
1635 просмотров

C programming if statement

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 wha...

0
голосов
9ответов
8854 просмотров

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.

1
голосов
5ответов
23318 просмотров

Why use if-else if in C++?

Why would you use if-else statements if you can make another if statement? Example with multiple ifs: input = getInputFromUser() if input is "Hello" greet() if input is "Bye" sayGoodbye() if input is "Hey" sayHi() Example with else-if: input = getInputFromUser() if input is "He...

0
голосов
9ответов
717 просмотров

What is the most terse syntax check for checking preconditions and then calling a switch statement?

What is the most terse syntax to combine a check for some preconditions with a switch statement? Can I combine an if/else and switch statement? if (!IsValid(text)) { DoSomeLogging(); } else { switch (text) { case "1": DoSomething(); break; case "2" DoSo...

4
голосов
6ответов
19526 просмотров

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...

0
голосов
2ответов
410 просмотров

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.

37
голосов
8ответов
33529 просмотров

How is if statement evaluated in c++?

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

21
голосов
23ответов
2014 просмотров

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...

0
голосов
4ответов
1971 просмотров

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 snippet. (its used in a calendar for availability matching) if (date.Year == now.Year && date.Month == now.Month && day == now.Day) { daysHtml.Append("<td class=...

0
голосов
7ответов
269 просмотров

Explicit or implicit execution control statement use

I sometimes use if (this._currentToolForeColor.HasValue) return this._currentToolForeColor.Value; else throw new InvalidOperationException(); other times I use if (this._currentToolForeColor.HasValue) return this._currentToolForeColor.Value; throw new InvalidOperationException(); ...

0
голосов
2ответов
1431 просмотров

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...

0
голосов
2ответов
280 просмотров

if statement issue, how to find element in body?

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 &am...

0
голосов
1ответов
90 просмотров

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...

0
голосов
1ответов
385 просмотров

MGrammar for parsing IF statement

I am building up a MGrammar spec to parse some pseudo code looking for particular bits of information. I have most of the spec working except for 1 cruical element. The pseudo code supports an if-then-else syntax and I have been unable to find a satisfactory way of parsing it. The exact cons...

3
голосов
11ответов
13622 просмотров

One line if statements

I was recently involved in an argument with a coworker involving one line if statements and wanted to see what stackoverflow thought. Do you feel that the statement should be written as: if(condition) { statement = new assignment; } OR if(condition) statement=new assignment; pleas...

2
голосов
4ответов
3769 просмотров

In MySQL why is this IF returning false?

In MySql, if the first argument of an IF() function is a string, why does it return false? SELECT IF('string', 'string', 'not string'); -- 'not string' Of course I could sort of fix this if I did IF(!ISNULL('string'), 'string', 'not string')) -- 'string' or IFNULL('string', 'not string');...

0
голосов
2ответов
819 просмотров

How to have the Xcode 3.1 compiler warn of assignment operator in an if statement?

I've tried searching the documentation and the internet as best as I'm able, but I haven't been able to get the Xcode compiler to issue a warning if the assignment operator is used in an if statement. I'm coming from RealBasic, where I've got an extremely strong habit of typing this sort of comp...

1
голосов
4ответов
6386 просмотров

Dealing with multiple Javascript IF statements

Is it possible to put multiple IF statements in Javascript? If so, I'm having a fair amount of trouble with the statement below. I was wondering if you can put another IF statement in between if (data == 'valid') AND else? I want to add another if data =='concept') between the two. if (data == '...

2
голосов
1ответов
1118 просмотров

Groovy 1.5.x / Grails 1.0.x If-Else statement bug

I have this code in a Grails 1.0.4 Groovy console: def devices = Device.getAll() def found = devices.findAll { if(it?.localNumber && it?.areaCode){ def pattern = ~".*${it.areaCode + it.localNumber}" def matches = "$msisdn" ==~ pattern println "$matches == msi...

0
голосов
4ответов
226 просмотров

Cleaning up PHP

Is there anyway I can clean up if($class == 2 AND $posts >=1){$showpost ="1";} else {$showpost ="$posts"; if($class == 3 AND $posts >=2){$showpost ="2";} else {$showpost ="$posts"; if($class == 4 AND $posts >=3){$showpost ="3";} else {$showpost ="$posts"; if($class == 5 AND $posts >=...