An "if" statement is a control structure in many programming languages that changes the execution flow depending on a condition.

328
votes
14answers
89k views

How do I test multiple variables against a value?

I'm trying to make a function that will compare multiple variables to an integer and output a string of three letters. I was wondering if there was a way to translate this into Python. So say:x=0...
11
votes
3answers
409 views

Why non-equality check of one variable against many values always returns true?

I have a variable v in my program, and it may take any value from the set of values"a", "b", "c", ..., "z"And my goal is to execute some statement only when v is not "x", "y", or "z".I have ...
1134
votes
23answers
2.8m views

How do I perform an IF…THEN in an SQL SELECT?

How do I perform an IF...THEN in an SQL SELECT statement?For example:SELECT IF(Obsolete='N' OR InStock='Y' ? 1 : 0) AS Saleable, * FROM Product
1143
votes
28answers
961k views

JavaScript check if variable exists (is defined/initialized)

Which method of checking if a variable has been initialized is better/correct?(Assuming the variable could hold anything (string, int, object, function, etc.))if (elem) { // or !elemorif (...
56
votes
1answer
2k views

Does ifelse really calculate both of its vectors every time? Is it slow?

Does ifelse really calculate both the yes and no vectors -- as in, the entirety of each vector?Or does it just calculate some values from each vector? Also, is ifelse really that slow?
249
votes
14answers
73k views

Why does python use 'else' after for and while loops?

I understand how this construct works:for i in range(10):print(i)if i==9:print("Too big - I'm giving up!")break;else:print("Completed successfully")But I don't ...
55
votes
16answers
22k views

Semicolon at end of 'if' statement

Today, after half an hour of searching for a bug, I discovered that it is possible to put a semicolon after an if statement instead of code, like this:if(a==b);// Do stuffWhich basically means ...
273
votes
14answers
258k views

Is “else if” faster than “switch() case”? [duplicate]

Possible Duplicate:Is there any significant difference between using if/else and switch-case in C#? I'm an ex Pascal guy, currently learning C#.My question is the following:Is the code below ...
140
votes
23answers
84k views

Advantage of switch over if-else statement

What's the best practice for using a switch statement vs using an if statement for 30 unsigned enumerations where about 10 have an expected action (that presently is the same action). Performance and ...
34
votes
2answers
31k views

Windows Batch Variables Won't Set

I think I ran into a bug in Window's batch scripting.I cannot set variables that are in an expanded if statement.Here is an isolated part of my script:@echo offset success=1set Version=12345...
338
votes
7answers
129k views

Is double square brackets [[ ]] preferable over single square brackets [ ] in Bash?

A co-worker claimed recently in a code review that the [[ ]] construct is to be preferred over [ ] in constructs like if [ "`id -nu`"="$someuser" ] ; then echo "I love you madly, $someuser"...
94
votes
8answers
81k views

What is the relative performance difference of if/else versus switch statement in Java?

Worrying about my web application's performances, I am wondering which of "if/else" or switch statement is better regarding performance?
196
votes
7answers
97k views

Else clause on Python while statement

I've noticed the following code is legal in Python. My question is why? Is there a specific reason?n=5while n !=0:print nn -=1else:print "what the..."
83
votes
6answers
13k views

How to prevent ifelse() from turning Date objects into numeric objects

I am using the function ifelse() to manipulate a date vector. I expected the result to be of class Date, and was surprised to get a numeric vector instead. Here is an example:dates <- as.Date(c('...
73
votes
13answers
108k views

In Java,Using switch statement with a range of value in each case?

In Java is it possible to write a switch statement where each case contains more than one value? For example (though clearly the following code won't work):switch (num) {case 1 .. 5:...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,