levo

Defining Data: Types, Variables and Classes

Relational and logical operators

  • 3 things to know
  • AS Unit 1

Overview

Value does a relational expression produce and short-circuit evaluation.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is short-circuit evaluation?

Key term

Explain why if (count != 0 && total / count > 5) is safe but reversing the two conditions is not.

Key term

Explain the difference between the logical AND written with two ampersands and the version written with one.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Which six relational operators are there, and what does each test?

    Model answer

    The relational operators test equal to, not equal to, less than, greater than, less than or equal to, and greater than or equal to.

  2. 2

    What type of value does a relational expression produce?

    Model answer

    A relational expression produces a boolean result, either true or false.

  3. 3

    Explain the difference between = and == in Java, and say what the compiler does with if (x = 5) where x is an int.

    Model answer

    A single equals sign assigns a value while a double equals sign tests for equality; Java rejects if (x = 5) because the assignment yields an int and the condition of an if must be a boolean.

  4. 4

    Which three logical operators are there, and what does each do?

    Model answer

    Logical AND is true only when both operands are true, logical OR is true when at least one operand is true, and logical NOT reverses the truth of a single operand.

  5. 5

    Given boolean a = true; boolean b = false; state the values of a && b, a || b and !a.

    Model answer

    The expression a && b is false because one operand is false, a || b is true because one operand is true, and !a is false because a is true.

  6. 6

    What is short-circuit evaluation?

    Model answer

    Short-circuit evaluation stops as soon as the result of a logical expression is settled, so the right operand of an AND is skipped when the left is false, and the right operand of an OR is skipped when the left is true.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A null is the of one.
absencepresencetype

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AA null means no value has been recorded.
BZero and an empty string are values.
CA null is the absence of a value.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Defining Data: Types, Variables and Classes, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.