Computer Science

Boolean Expressions

Boolean expressions are logical expressions that evaluate to either true or false. They are commonly used in programming and computer science to make decisions and control the flow of a program. Boolean expressions often involve the use of logical operators such as AND, OR, and NOT to compare values and conditions.

Written by Perlego with AI-assistance

2 Key excerpts on "Boolean Expressions"

  • The PHP Workshop
    eBook - ePub

    The PHP Workshop

    A New, Interactive Approach to Learning PHP

    • Alexandru Busuioc, David Carr, Markus Gray, Vijay Joshi, Mark McCollum, Bart McLeod, M A Hossain Tonu(Authors)
    • 2019(Publication Date)
    • Packt Publishing
      (Publisher)
    That logic could test a certain value, could be a comparison of values, or could test a logical relationship, and it can be written as an expression. The expression is evaluated as a Boolean value; that is, true or false by the branching and looping structures. For branching, the expression serves as an entry check for that branch so that we can decide whether to choose that branch of code or not. For looping, the expression might serve as an entry or exit check for that loop so that we can decide how many times the loop should iterate. For example, to email a list of persons, we can write an expression to determine the size of the list so that we set how many times we do the emailing task and write another expression that checks the email address validity to send the email. A Boolean expression is an expression that produces a result of either true or false. A Boolean expression can consist of Boolean constants, Boolean data in variables, logical and comparison expressions, and even other types of expressions that yield a Boolean true or false. A Boolean expression uses the logical operators not, and, and or to check the truthiness or untruthiness or the falseness of any statement. Consider a fruit analogy: " I love apples ". The expression is true if apple is a fruit. What about " I love both apples and oranges "? The expression is true if both " I love apples " and " I love oranges " are true. Comparison operators also play a role in a Boolean expression when we need to compare two values to identify whether they are equal, or one is greater or less than the other
  • Computer Programming for Beginners
    eBook - ePub
    7 Arithmetic, Relational, and Logical Expressions Introduction to Expressions
    As we have noted in Chapter 6 , expressions are used in statements. Almost every statement contains at least one expression. Merriam Webster’s dictionary defines an expression generally as “an act of expressing” and “an act of making your thoughts, feelings etc. known by speech, writing or some other method,” and in the context of computer programming, thus, “a mathematical or logical symbol or a meaningful combination of symbols”. Wikipedia defines an expression thus: “an expression in computer programming is a combination of explicit values, constants, variables, operators and functions, that are interpreted according to the particular rules of precedence and of association for the specific programming language.”
    Let us enumerate the attributes of expressions in the context of computer programming to understand them better: 1.  An expression may consist of at least two variables, a constant, or a combination of variables and constants. 2.  The variables and constants in the expression are combined using mathematical, relational, or logical symbols, generally referred to as “operators.” 3.  The expression is amenable to evaluation using arithmetic, relational, or logical rules.
    4.  The evaluation of an expression in a statement yields only one value that can be used for assignment to a variable or in programmed decision making. That is, expressions can be used in assignment statements and control statements. Expressions are not used in a stand-alone mode.
    5.  Expressions, when used in assignment statements, must be on the right-hand side of the assignment symbol. An expression can never be on the left-hand side of an assignment symbol.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.