short-circuiting Questions
1
Solved
Is left-to-right evaluation of logical operators (&& ||) guaranteed?
Let's say I have this:
SDL_Event event;
if (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
// do ...
Ruyle asked 15/4, 2011 at 22:39
7
If I write two SELECT statements in a IF EXISTS condition with a AND clause in between these select queries, does both queries get executed even if the first SELECT returns false?
IF EXISTS (SELEC...
March asked 4/4, 2011 at 18:54
3
Solved
When using the ?? operator in C#, does it short circuit if the value being tested is not null?
Example:
string test = null;
string test2 = test ?? "Default";
string test3 = test2 ?? test.ToLower...
Lytic asked 15/3, 2011 at 22:36
4
Solved
While performing a check if there's a camera present and enabled on my windows mobile unit I encountered something I don't understand.
The code looks like this:
public static bool CameraP(){
r...
Thruway asked 8/3, 2011 at 13:31
7
Solved
When encountering a (bool1 && bool2), does c++ ever attempts to check bool2 if bool1 was found false or does it ignore it the way PHP does?
Sorry if it is too basic of a question, bu...
Eolanda asked 6/3, 2011 at 17:5
2
Solved
Following the usual short-circuit evaluation question, does short-circuit evaluation work for parameters built and sent against nil objects? Example:
NSMutableArray *nil_array = nil;
....
[nil_arr...
Imperfection asked 13/2, 2011 at 16:37
5
Solved
I'm new to Haskell, and I'm trying a bit:
isPrime :: Integer->Bool
isPrime x = ([] == [y | y<-[2..floor (sqrt x)], mod x y == 0])
I have a few questions.
Why when I try to load the .hs, ...
Topic asked 27/12, 2010 at 20:1
2
Solved
For example:
def foo():
print 'foo'
return 1
if any([f() for f in [foo]*3]):
print 'bar'
I thought the above code should output:
foo
bar
instead of :
foo
foo
foo
bar
Why ? how can...
Cheeks asked 29/11, 2010 at 8:18
10
Solved
Does Java check all arguments in "&&" (and) operator even if one of them is false?
I have such code:
if(object != null && object.field != null){
object.field = "foo";
}
Assume that object is null.
Does this code result in nullPointerException or just if statement wo...
Denticle asked 12/11, 2010 at 10:36
3
Solved
While debugging javascript written by someone else, I came across some code that I've not seen before. Here's a sample:
function doSomething() {
//doing something here...
}
function doItNow() {
...
Equi asked 3/11, 2010 at 20:51
4
Solved
I've got a query that I've just found in the database that is failing causing a report to fall over. The basic gist of the query:
Select *
From table
Where IsNull(myField, '') <> ''
And IsNu...
Evyn asked 21/9, 2010 at 12:43
4
Solved
If I have the following ...
a OrElse b
... and a is True then clearly b is never evaluated. But if I add an Or, then what?
a OrElse b Or c
Does/should c get evaluated? And what if I put in s...
Hogue asked 9/9, 2010 at 14:45
1
Solved
I wrote a simple script to solve a "logic puzzle", the type of puzzle from school where you are given a number of rules and then must be able to find the solution for problems like "There are five ...
Improve asked 4/8, 2010 at 13:8
2
Solved
Do we have any operator in C# by which I can avoid short circuit evaluation and traverse to all the conditions.
say
if(txtName.Text.xyz() || txtLastName.Text.xyz())
{
}
public static bool xyz...
Siler asked 14/7, 2010 at 8:2
2
Solved
Sorry if this sounds like a really silly question.
But I Googled the web and also Googled specifically both the php.net site and the stackoverflow.com site.
I know PHP does short circuit lazy eval...
Fulcrum asked 10/7, 2010 at 21:36
2
Solved
In other words, do the following two statements behave the same way?
isFoobared = isFoobared && methodWithSideEffects();
isFoobared &= methodWithSideEffects();
I realize I could just...
Generate asked 30/6, 2010 at 18:25
4
Solved
I'm trying to find out how I can do an "early return" in a scheme procedure without using a top-level if or cond like construct.
(define (win b)
(let* ((test (first (first b)))
(result (every (l...
Rajkot asked 12/3, 2010 at 16:50
4
Solved
I tried something along the lines of:
if(myString != nil && myString.length) { ... }
And got:
-[NSNull length]: unrecognized selector sent to instance
Does Objective-C not short-circui...
Cyrilla asked 13/1, 2010 at 22:23
3
Solved
Suppose I want to check a bunch of objects to make sure none is null:
if (obj != null &&
obj.Parameters != null &&
obj.Parameters.UserSettings != null) {
// do something with o...
Faefaeces asked 16/12, 2009 at 20:40
7
Solved
I thought Java had short circuit evaluation, yet this line is still throwing a null pointer exception:
if( (perfectAgent != null) && (perfectAgent.getAddress().equals(entry.getKey())) ) {
...
Paresh asked 29/11, 2009 at 21:4
8
Solved
I'm new to c++ and am curious how the compiler handles lazy evaluation of booleans. For example,
if(A == 1 || B == 2){...}
If A does equal 1, is the B==2 part ever evaluated?
Crosscrosslet asked 25/11, 2009 at 18:39
2
Solved
Given:
WHERE (@Id Is NULL OR @Id = Table.Id)
If @Id is null: the expression evaluates to true. Does the second part @Id = Table.Id still get considered? or is it sufficient that the expression e...
Eastbound asked 19/11, 2009 at 5:10
5
Solved
Which of these subroutines is not like the other?
sub or1 {
my ($a,$b) = @_;
return $a || $b;
}
sub or2 {
my ($a,$b) = @_;
$a || $b;
}
sub or3 {
my ($a,$b) = @_;
return $a or $b;
}
sub or...
Kennedy asked 3/10, 2009 at 1:43
15
Solved
I have seen something like the following a couple times... and I hate it. Is this basically 'cheating' the language? Or.. would you consider this to be 'ok' because the IsNullOrEmpty is evaluated f...
Raceway asked 7/5, 2009 at 20:47
10
Solved
I have a couple of methods that return a bool depending on their success, is there anything wrong with calling those methods inside of the IF() ?
//&& makes sure that Method2() will only g...
Harrier asked 23/2, 2009 at 21:6
© 2022 - 2024 — McMap. All rights reserved.