Skip to content

Control Flow

Dave Luk edited this page Dec 25, 2017 · 7 revisions

Overview

In this lesson, we will learn about ways to control how a program behave.

New Concepts

Boolean Values

Boolean is a kind of datatype. It have only two values: True and False. Now you can think of your true-false questions on your tests as booleans!

Boolean Operators

Boolean operators are symbols that will give us results in boolean. Let's first introduce them:

Equals ==

This is used to check if 2 variable/values are same. For example:

5 == 5  # This give us True
5 == 0 # This give us False
Not equals !=

Just like equals, this checks for exact opposite of equals:

5 != 5  # This give us False
5 != 0 # This give us True
Greater than >

This checks for if a value/variable is greater than another:

5 > 5  # This give us False
5 > 0 # This give us True
Less than <

This checks for if a value/variable is less than another:

5 < 5  # This give us False
0 < 5 # This give us True
Greater than or equals >=

This checks for if a value/variable is greater than or equals another:

5 >= 5  # This give us True
0 >= 5 # This give us False
Less than or equals <=

This checks for if a value/variable is less than or equals another:

5 <= 5  # This give us True
0 <= 5 # This give us True

Conditions

Flow of Control

Import

Activity

Caesar Cipher

Summary

Practice Problems