Questions tagged [boolean-expression]

A boolean expression is an expression in a programming language that produces a boolean value when evaluated, i.e. one of true or false.

In computer science, a Boolean expression is an expression in a programming language that produces a Boolean value when evaluated, i.e. one of true or false. A Boolean expression may be composed of a combination of the Boolean constants true or false, Boolean-typed variables, Boolean-valued operators, and Boolean-valued functions.

1049 questions
41
votes
3 answers

boolean variable values in PHP to javascript implementation

I've run into an odd issue in a PHP script that I'm writing-- I'm sure there's an easy answer but I'm not seeing it. I'm pulling some vars from a DB using PHP, then passing those values into a Javascript that is getting built dynamically in PHP.…
julio
  • 6,630
  • 15
  • 60
  • 82
41
votes
9 answers

XOR of three values

What is the simplest way to do a three-way exclusive OR? In other words, I have three values, and I want a statement that evaluates to true IFF only one of the three values is true. So far, this is what I've come up with: ((a ^ b) && (a ^ c) && !(b…
Josh
  • 1,387
  • 2
  • 13
  • 15
40
votes
7 answers

if (boolean == false) vs. if (!boolean)

Possible Duplicate: Is it bad to explicitly compare against boolean constants e.g. if (b == false) in Java? In this NotePadProvider sample code, I noticed that the author chose the form: if (values.containsKey(NoteColumns.CREATED_DATE) ==…
ateiob
  • 9,016
  • 10
  • 44
  • 55
35
votes
5 answers

Is there any reason for "Boolean.TRUE.equals(x)" in Java?

I've come across this code in one of the projects I'm working on (This is in Java) if (Boolean.TRUE.equals(foo.isBar())) Foo#isBar() is defined as boolean isBar(), so it can't return null Is there really any reason why it should be written that…
user1508893
  • 9,223
  • 14
  • 45
  • 57
33
votes
4 answers

When to prefer `and` over `andalso` in guard tests

I am curious why the comma ‹,› is a shortcut for and and not andalso in guard tests. Since I'd call myself a “C native” I fail to see any shortcomings of short-circuit boolean evaluation. I compiled some test code using the to_core flag to see what…
Kijewski
  • 25,517
  • 12
  • 101
  • 143
33
votes
6 answers

Ruby: Boolean attribute naming convention and use

Learning ruby. I'm under the impression that boolean attributes should be named as follows: my_boolean_attribute? However, I get syntax errors when attempting to do the following: class MyClass attr_accessor :my_boolean_attribute? def…
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
28
votes
5 answers

Java boolean |= operator

Recently I saw a code using this: boolean val = something(); val |= somethingElse(); Interesting part is |= (binary like) operator made on boolean primitive type. It surprised me that |= exist for boolean, as if it was integer type, and searched…
25
votes
4 answers

Boolean expression order of evaluation in Java?

Suppose I have the following expression String myString = getStringFromSomeExternalSource(); if (myString != null && myString.trim().length() != 0) { ... } Eclipse warns me that myString might be null in the second phrase of the boolean expression.…
daveslab
  • 10,000
  • 21
  • 60
  • 86
24
votes
2 answers

What is the correct way to check for False?

Which is better? (and why?) if somevalue == False: or if somevalue is False: Does your answer change if somevalue is a string?
patchwork
  • 1,161
  • 3
  • 8
  • 23
24
votes
7 answers

What's the difference between the dual and the complement of a boolean expression?

Its the same thing right? Or is there a slight difference? I just wanna make sure I'm not misunderstanding anything.
22
votes
6 answers

Boolean expression parser in Java

Are there any jJava libraries or techniques to parsing boolean expressions piecemeal? What I mean is given an expression like this: T && ( F || ( F && T ) ) It could be broken down into a expression tree to show which token caused the 'F' value,…
javamonkey79
  • 17,443
  • 36
  • 114
  • 172
20
votes
4 answers

Python boolean expression and or

In python if you write something like foo==bar and spam or eggs python appears to return spam if the boolean statement is true and eggs otherwise. Could someone explain this behaviour? Why is the expression not being evaluated like one long…
Zxaos
  • 7,791
  • 12
  • 47
  • 61
20
votes
5 answers

Why are products called minterms and sums called maxterms?

Do they have a reason for doing so? I mean, in the sum of minterms, you look for the terms with the output 1; I don't get why they call it "minterms." Why not maxterms because 1 is well bigger than 0? Is there a reason behind this that I don't know?…
19
votes
6 answers

Simplify boolean expression algorithm

Anybody knows of an algorithm to simplify boolean expressions? I remember the boolean algebra and Karnaught maps, but this is meant for digital hardware where EVERITHING is boolean. I would like something that takes into account that some…
Olmo
  • 4,257
  • 3
  • 31
  • 35
18
votes
5 answers

Why does Perl use the empty string to represent the boolean false value?

When evaluating an expression in a scalar (boolean) context, Perl uses the explicit value 1 as a result if the expression evaluates to true and the empty string if the expression evaluates to false. I'm curious why Perl uses the empty string to…
Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
1
2
3
69 70