-5

What does this mean:

if (value > 10 || value == 20) {

Any answer would be nice. thanks!

camo5hark
  • 214
  • 1
  • 5

3 Answers3

1

It means OR. If one of these two options will be true, the if statement will be true.

Note:
both && = AND and || = OR have short evaluation. So if there if other conditions can't change status it won't continue.

http://www.cs.columbia.edu/~lennox/3101-03/class1-slides/logical.html

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html :

The && and || operators perform Conditional-AND and Conditional-OR operations on two boolean expressions. These operators exhibit "short-circuiting" behavior, which means that the second operand is evaluated only if needed.

&& Conditional-AND || Conditional-OR

user1097772
  • 3,499
  • 15
  • 59
  • 95
  • @BackSlash see this link and the first answer http://stackoverflow.com/questions/8759868/java-logical-operator-short-circuiting – SteelToe Dec 30 '16 at 14:44
  • @MarrieteCowby12 I know the operator short-circuits, but it's a side effect due to logical operations. Those are called conditional operators, not short-circuiting operators. And `|` is not a *plain* or, it's a bitwise or, which is different. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html – BackSlash Dec 30 '16 at 14:46
  • `|` is a "plain OR" - not a bitwise OR when used with boolean operands https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.22.2 – Lew Bloch Dec 30 '16 at 20:51
  • @LewBloch He can easy google it when he knows now what is it. But link added. And in most cases you really don't care that it is short-circuited. Java have only one logical or and the operator for it is ||. Fact that is short-circuited is just way how is logical or implemented in java. It is just optimalimalization which can speed up resolution of long conditions if the result is known earlier so there is not needed to evaluate the rest. Both AndriiAbramov and LewBloch flagged for rude behavior. – user1097772 Jan 04 '17 at 08:52
1

|| is a short circuit 'or' boolean operator

If the expression on the left hand side evaluates to true there is no need to evaluate the expression on the right as the condition has already been met

hardillb
  • 54,545
  • 11
  • 67
  • 105
0

It is an OR conditional Statement. In your particular case, the statements inside the if block will be executed, if the value is more than 10 or if it is equal to 20. Hope this explains what you intended to ask.