All Questions

321
votes
14answers
85863 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
405 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 tri...
1105
votes
22answers
2786758 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
1108
votes
28answers
936038 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 !elem or if (type...
56
votes
1answers
1803 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?
243
votes
14answers
71102 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'...
55
votes
16answers
21229 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 stuff Which basically means...
265
votes
14answers
253626 views

Is "else if" faster than "switch() case"?

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 ...
136
votes
23answers
83250 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 ...
32
votes
2answers
30558 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 off set success=1 set Version=12345 ...

Previous Next