Topic 1 - Variables and Data Types
Topic 2 - Conditionals and Strings
Topic 3 - Loops
Topic 4 - Arrays
Topic 5 - File Handling
Semester 1 Projects
Topic 6 - Classes/Objects and Methods
Topic 7 - ArrayLists
Semester Projects

Compound Boolean Expressions

&& and ||

You can use a compound statement if you want to make sure that two or more conditionals are true or not before executing the associated block of code. Let’s take a look at an example:

In the example above, we have two booleans, cleanedRoom and didHomework. && can be used to check if BOTH variables are true. If and only if they are both true, then the code inside the if-block runs.

But what if we don’t want to be as strict? What if we want the code to run if one of them is true, or if both are true? We instead use || (OR) as below.

We can also use && and || to check for numeric values and combine them with other operators (<, >, >=, <=, etc) to create complex checks.

! operator

Sometimes we’ll want to negate a boolean. So it’s easier to say, if this is NOT true, then go ahead and run the code. This can get quite tricky, so it’s very important to name your variables well.