logical-operators

Why does C not have a logical assignment operator?

Possible Duplicate: Why doesnt c++ have &&= or ||= for booleans? I had the need to code a statement of the form a = a || expr; where expr should be evaluated and the result be assigned to a iff a is not set. this relies on the logical OR's shortcircuiting capabilities. The shorter way to write the above would, of course, b...

Logical NOT (!) operator won't work with bitwise statement

I am attempting to determine if I can compute the sum of two 32 bit integers without overflow, while making use of only certain bitwise and other operators. So, if the integers x and y can be added without overflow, the following code should return 1, and 0 otherwise. (((((x >> 31) + (y >> 31)) & 2) >> 1)) However, it returns 0 when ...

How does the `||` work in Perl?

How does the || works in Perl? I want to achieve c style || operation. @ARRAY=qw(one two THREE four); $i=0; if(($ARRAY[2] ne "three")||($ARRAY[2] ne "THREE")) #What's the problem with this { print ":::::$ARRAY[2]::::::\n"; } while(($ARRAY[$i] ne "three")||($ARRAY[$i] ne "THREE")) #This goes to infinite loop { pri...

In Ruby, should we always use "&&", "||" instead of "and", "or" unless for special situations?

Is it true that in most cases, in Ruby, it is best to use &&, || instead of and, or, unless it is some special situations. I think one of Ruby's design principles is to have least surprises as possible, so using and, or or actually have some surprises... such as and not having a higher precedence than or, while && has a higher precedenc...

How to define more one condition in a While

Hi, I would like something like that : While Not RdoRst.EOF And RdoRst(2) = "Foo" cboComboBox.AddItem RdoRst(1) cboComboBox.ItemData(cboComboBox.NewIndex) = RdoRst(0) RdoRst.MoveNext Wend I want that the expression 1 (Not RdoRst.EOF) is evaluated first. Then if it returns true, the expression 2 is evaluated t...

Does && in c++ behave the same as && in Java?

Hi guys, my question is essentially in the title. Basically I've learned that in Java the && operator acts like a short circuit, so that if the first condition evaluates to false it doesn't look at the rest of the statement. I assumed this was the case in c++ but I'm writing a bit of code which first checks that an index has not exceeded...

Order of operators in IF statement

I often do this when necessary to prevent a null pointer exception: // Example #1 if (cats != null && cats.Count > 0) { // Do something } In #1, I've always just assumed that the cats != null needs to be first, because order of operations evaluate from left to right. However, unlike example #1, now I want to do something if the obj...

What does '-a' do in Unix Shell scripting

What does -a mean in the below line. if [ "${FILE_SYSTEM}" != "xyz" -a "${FILE_SYSTEM}" != "abc" ] ...

Whats the difference between "<>" and "!="?

Normally I would use !=, then when I saw this sign <> it means not equal to as well. After that, I went to search on Google, what's the difference between <> and !=. But I could not find the answer. Anyone care to explain? Edit: Thanks for the answers guys =) ...

&&= and ||= operators

Possible Duplicates: Why doesn't Java have compound assignment versions of the conditional-and and conditional-or operators? (&&=, ||=) Why does a &&= Operator not exist? Today at work I wrote the following LOC (the real identities of b and b1 are confidential :) b &&= b1; // meaning b = b && b1; I stared at it for a co...

What is the result of Perl's &&?

When I try this: $a = 1; $b = 2; print ($a && $b) . "\n"; The result is 2. Why? ...

Scheme Logical Operators

I have a conditional and I want to test to see if two things are true. How can I do an equivalent of && or || from java in scheme? ...

Performing a logical not ! using only bitwise operations.

Possible Duplicate: Check if a number is non zero using bitwise operators in C. Hello everyone, I am working on a project and I need a little help with a function. We need to write a function that performs the logical not, !, using only the following bitwise operators: ~ & ^ | + << >> I'm not even sure where to begin. ...