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].

85 questions
906
votes
10 answers

Python's equivalent of && (logical-and) in an if-statement

Here's my code: def front_back(a, b): # +++your code here+++ if len(a) % 2 == 0 && len(b) % 2 == 0: return a[:(len(a)/2)] + b[:(len(b)/2)] + a[(len(a)/2):] + b[(len(b)/2):] else: #todo! Not yet done. :P return I'm getting an error…
delete
271
votes
3 answers

Boolean operators && and ||

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"…
SFun28
  • 32,209
  • 43
  • 123
  • 233
77
votes
6 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
  • 58,815
  • 45
  • 146
  • 176
60
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
  • 1,793
  • 3
  • 18
  • 20
54
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,152
  • 1
  • 9
  • 20
44
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 朕會功夫
  • 84,678
  • 41
  • 166
  • 228
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
  • 771
  • 1
  • 9
  • 21
13
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
  • 21,352
  • 30
  • 113
  • 196
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
  • 16,343
  • 69
  • 163
  • 271
7
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…
Luxor001
  • 2,625
  • 1
  • 16
  • 29
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
  • 7,746
  • 2
  • 23
  • 45
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
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
  • 4
6
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
  • 14,523
  • 14
  • 72
  • 123
5
votes
7 answers

How to display anything in php in between particular time duration?

I have a php code as shown below in which I want to display anything in between two calendar days of the week. The values coming inside $data->{"select_start_day"}; $data->{"start_time"}; $data->{"select_end_day"}; and $data->{"end_time"}; is…
flash
  • 1,564
  • 3
  • 27
  • 87
1
2 3 4 5 6