Brandon Rozek

Lecture for February 1st

Control Structures

In this class we will talk about three types of control structures

Sequential is what is most familiar to us. Write the lines from top to bottom and it executes it in that order


Selection depends on the question of if.

If it is raining, wear boots

if (raining) {
  wearingBoots = true;

If you want something to happen also when it is not true, consider an if-else statement

If the light is off, turn it on.

Otherwise, turn it on

if (lightIsOn) {
  lightIsOn = false;
} else {
  lightIsOn = true;

Sometimes you can have multiple branches depending on a condition. Let us take a stop light as an example

if (light == "red") {
} else if (light == "yellow") {
} else {

String comparison

There is a specific method in the String class when it comes to checking for string equality

boolean equals(String s)

Let us look at an example

String word = "hello";
boolean ans = word.equals("hello"); // Returns true
boolean ans2 = word.equals("Hello"); // Returns false