DEV Community

Mackenly Jones
Mackenly Jones

Posted on • Originally published at crtv.dev on

Java Loop Boolean Expressions

Java Loop Boolean Expressions

Boolean expressions are used to represent conditions required for all loops. It may not be obvious at first, but even "for" loops contain Boolean expressions used to evaluate if their conditions have been met.

Java separates the operators used to construct boolean expressions into two categories: Comparison Operators and Logical Operators.

Comparison operators include:

  • == Equal to operator used to determine equality.
  • != Not equal to operator used to determine inequality.
  • > Greater than operator used to determine if the proceeding value is mathematically greater than the following value.
  • < Less than operator used to determine if the proceeding value is mathematically less than the following value.
  • >= Greater than or equal to combines the behavior of the greater than operator and equal to operator, allowing for values that are greater than or equal to another value.
  • <= Less than or equal to combines the behavior of the less than operator and equal to operator, allowing for values that are less than or equal to another value.

Logical operators include:

  • && Logical and returns true if both input statements or values are true.
  • || Logical or returns true if at least one of the input statements or values is true.
  • ! Logical not, negates the following statement or value. Meaning if the following value is true, it will return false and vice versa.

Top comments (0)