Questions tagged [and-operator]

The 'and' operator can refer to either a logical AND (evaluating to true if all the compared statements are true) or a bitwise AND (comparing the bits of an integer). For the latter use tag [bitwise-and].

96 questions
324
votes
5 answers

Difference between Boolean operators && and & and between || and | in R

According to the R language definition, the difference between & and && (correspondingly | and ||) is that the former is vectorized while the latter is not. According to the help text, I read the difference akin to the difference between an "And"…
Suraj
  • 35,905
  • 47
  • 139
  • 250
86
votes
7 answers

Javascript AND operator within assignment

I know that in JavaScript you can do: var oneOrTheOther = someOtherVar || "these are not the droids you are looking for..."; where the variable oneOrTheOther will take on the value of the first expression if it is not null, undefined, or false. In…
Alex
  • 64,178
  • 48
  • 151
  • 180
78
votes
4 answers

Regex AND operator

Based on this answer Regular Expressions: Is there an AND operator? I tried the following on http://regexpal.com/ but was unable to get it to work. What am missing? Does javascript not support it? Regex: (?=foo)(?=baz) String: foo,bar,baz
user366735
  • 2,183
  • 3
  • 21
  • 20
63
votes
7 answers

How does C++ handle &&? (Short-circuit evaluation)

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, but I really could not find a mentioning of that neither in Schildt…
Aleksandrs Ulme
  • 1,262
  • 1
  • 12
  • 21
46
votes
5 answers

What is "x && foo()"?

I saw somewhere else said, x && foo();  is equal to if(x){ foo(); } I tested it and they really did the same thing. But why? What exactly is x && foo()?
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
17
votes
2 answers

how can I use AND operator in IF statement in nginx?

I'm trying to cache the request based on the response header. Right now my desire condition is if the response has both 2 headers client-device and client-location, then the response should be cached on nginx side So I tried with this code if…
zadops
  • 506
  • 1
  • 3
  • 10
14
votes
10 answers

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 won't be executed? If it does, how to refactor this code to be…
pixel
  • 24,905
  • 36
  • 149
  • 251
14
votes
5 answers

Operator precedence for And/&& in Ruby

I have a question regarding the and/&&/= keywords in Ruby. The ruby docs say that the precedence for the mentioned keywords is: (1)&&, (2)=, (3)and. I have this snippet of code I wrote: def f(n) n end if a = f(2) and b = f(4) then puts "1)…
Alon
  • 801
  • 1
  • 10
  • 22
12
votes
3 answers

PHP: if !empty & empty

So i have this form.. With 2 fields. "Youtube" and "link" I want to do if you have filled in YouTube, it should do this: if(!empty($youtube)) { if ($pos === false) { echo "Du skal indtaste youtube et URL, som starter med…
Karem
  • 17,615
  • 72
  • 178
  • 278
11
votes
5 answers

Using & (bitwise AND operator) in Angular ng-if expressions

I can't get the & operator to work in an Angular ng-if expression (to use with some bit flags). Suppose we have some HTML like this:
If value equals 3, then the bitwise operation should return 2 and thus a true…
illeb
  • 2,942
  • 1
  • 21
  • 35
7
votes
2 answers

redefine __and__ operator

Why I can't redefine the __and__ operator? class Cut(object): def __init__(self, cut): self.cut = cut def __and__(self, other): return Cut("(" + self.cut + ") && (" + other.cut + ")") a = Cut("a>0") b = Cut("b>0") c =…
Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141
6
votes
5 answers

Short-circuit evaluation via the AND operator in PHP

I'm trying to improve my coding ninja h4x skills, and I'm currently looking at different frameworks, and I have found sample code that's pretty hard to google. I am looking at the FUEL framework used in a project. The sample I don't understand is…
Jan Dragsbaek
  • 8,078
  • 2
  • 26
  • 46
6
votes
4 answers

use of **and** operator within an **if statement**

I was directed to this website by a friend. I am trying to use and in Delphi, but I seem to be doing something wrong. Is there something you need to put in uses? I have the following code: procedure TForm1.Button1Click(Sender:…
gerard
  • 65
  • 1
  • 1
  • 3
6
votes
2 answers

R - Find all vector elements that contain all strings / patterns - str_detect grep

Sample data files.in.path = c("a.4.0. name 2015 - NY.RDS", "b.4.0. name 2016 - CA.RDS", "c.4.0. name 2015 - PA.RDS") strings.to.find = c("4.0", "PA") I want the logical vector that shows all elements that…
LWRMS
  • 547
  • 8
  • 18
6
votes
3 answers

C Relational Operator Output

#include void main() { int x = 1, y = 0, z = 5; int a = x && y || z++; printf("%d", z); } This yields output as 6 whereas #include void main() { int x = 1, y = 0, z = 5; int a = x && y && z++; …
Srijan Kumar
  • 71
  • 1
  • 1
  • 4
1
2 3 4 5 6 7