logical-operators

Using AND vs && in a for loop (Not related to precedence?)

Why is it that this code prints "Hello!" four times and then prints "1": <?php for ($i=1 AND $blah=1; $i<5; $i++) echo("Hello!"); echo($blah); ?> While this doesn't print out "Hello!" at all and then prints "1": <?php for ($i=1 && $blah=1; $i<5; $i++) echo("Hello!"); echo($blah); ?> I know AND and && have different precedences, but...

If Statement not working with And (&&) Operator

Hi all! I'm having a hard time writing up what seems should be a simple if statement! I need it to say if mod does not equal a, b, or c - then do this. Here is what I was trying but have been unsuccessful: var mod = CURRENT_MODULE_ID; if (mod != "5827289" && mod != "5195103" && mod != "5181422") { doSomething(); } When I type this ...

How to verify a datatype mismatch? (not=== false)

What's the opposite of triple equals matching in PHP? $mail_01 = filter_var($mail_01, FILTER_VALIDATE_EMAIL); if($mail !== false){ echo "Email address required"; } Is the !== usage correct? Thanks for any help. ...

The written versions of the logical operators.

This is the only place I've ever seen and, or and not listed as actual operators in C++. When I wrote up a test program in NetBeans, I got the red underlining as if there was a syntax error and figured the website was wrong, but it is NetBeans which is wrong because it compiled and ran as expected. I can see ! being favored over not but...

Usage of ||, OR in PHP

I have the following code which redirect pages depends on $path. ... $path = $this->uri->segment(3); $pathid = $this->uri->segment(4); if($path=='forsiden'){ redirect('','refresh'); }elseif($path =='contact'){ redirect('welcome/kontakt','refresh'); }elseif($path =='illustration'){ $thi...

R: How to pass a list of selection expressions (strings in this case) to the subset function?

Here is some example data: data = data.frame(series = c("1a", "1b", "1e"), reading = c(0.1, 0.4, 0.6)) > data series reading 1 1a 0.1 2 1b 0.4 3 1e 0.6 Which I can pull out selective single rows using subset: > subset (data, series == "1a") series reading 1 1a 0.1 And pull out multiple rows usin...

unusual ternary operation

Hi, I was asked to perform this operation of ternary operator use: $test='one'; echo $test == 'one' ? 'one' : $test == 'two' ? 'two' : 'three'; Which prints two (checked using php). I am still not sure about the logic for this. Please, can anybody tell me the logic for this. ...

Short circuiting statement evaluation -- is this guaranteed? [C#]

Hi everyone, Quick question here about short-circuiting statements in C#. With an if statement like this: if (MyObject.MyArray.Count == 0 || MyObject.MyArray[0].SomeValue == 0) { //.... } Is it guaranteed that evaluation will stop after the "MyArray.Count" portion, provided that portion is true? Otherwise I'll get a null exception...

&& Operation in .NET

Which one out of the following two should be preferred while doing && operation on two values. if (!StartTime.Equals(DateTime.MinValue) && !CreationTime.Equals(DateTime.MinValue)) Or if (!(StartTime.Equals(DateTime.MinValue) && CreationTime.Equals(DateTime.MinValue)) What is the difference between the two? ...

Null-coalescing operator and operator && in C#

Is it possible to use together any way operator ?? and operator && in next case: bool? Any { get { var any = this.ViewState["any"] as bool?; return any.HasValue ? any.Value && this.SomeBool : any; } } This means next: if any is null then this.Any.HasValue return false if any has value, then it returns value cons...

Finding a smaller value and swap values in php

Hi $var1 = 22; $var2 = 10; echo $var1 = ($var1 < $var2) ? $var1 : $var2; //smaller var echo '<br />'; echo $var2 = ($var1 > $var2) ? $var1 : $var2; //greater var I expect it to print 10 and 22 but it prints 10 and 10. any ideas what I am doing wrong? Thanks UPDATE Thanks all. $min = min($var1, $var2); $...

What is the point of the logical operators in C?

I was just wondering if there is an XOR logical operator in C (something like && for AND but for XOR). I know I can split an XOR into ANDs, NOTs and ORs but a simple XOR would be much better. Then it occurred to me that if I use the normal XOR bitwise operator between two conditions, it might just work. And for my tests it did. Consider...

SQL with Regular Expressions vs Indexes with Logical Merging Functions

Hello All, I am trying to develop a complex textual search engine. I have thousands of textual pages from many books. I need to search pages that contain specified complex logical criterias. These criterias can contain virtually any compination of the following: A: Full words. B: Word roots (semilar to stems; i.e. all words with certa...

logical operators evaluation in return statemnet in python

hi, how does this execute: def f(x): return x>0 and (x%2)+f(x/2) or 0 x is an array ,for instanse,[1, 1, 1, 3] thank u ...

when to use === operator check in JavaScript?

Possible Duplicate: Javascript === vs == : Does it matter which equal operator I use? As the title states; when should you use the === operator check when using JavaScript, and when not to. Edit: more complete answer found here. Thanks to Mark Byers for pointing it out. _L ...

short hand for chaining logical operators in javascript?

Is there a better way to write the following conditional in javascript? if ( value == 1 || value == 16 || value == -500 || value == 42.42 || value == 'something' ) { // blah blah blah } I hate having all of those logical ORs strung together. I'm wondering if there is some kind of shorthand. Thanks! ...

What is the difference between logical and conditional AND, OR in C#?

Possible Duplicate: What is the diffference between the | and || or operators? Logical AND and OR: (x & y) (x | y) Conditional AND and OR: (x && y) (x || y) I've only known about conditional operands up to this point. I know what it does and how to apply it in if-statements. But what is the purpose of logical operands? ...

Javascript AND operator with assignment

Hi there, I know that in Javascript you can do: var oneOrTheOther = someOtherVar || "these are not the droids you are looking for...move along"; where the variable oneOrTheOther will take on the value of the first expression if it is not null, undefined, or false. In which case it gets assigned to the value of the second statement. ...

Can I simplify this conditional statement, which uses the logical negation operator?

Sorry if this is a "Logical Operators 101" kind of question. I've been staring at my screen for 15 minutes trying to wrap my head around it, but I'm stuck. Is there a more concise/elegant way to phrase the following (this is JavaScript syntax, but it's not a language-dependent question): if (!something && !something_else) { // do som...

Ruby logical operators

Possible Duplicate: Is there any wisdom behind and, or operators in Ruby ? What is the difference, if any, between the following pairs of logical operators? && vs. and || vs. or ...