Chapter Table of Contents

Ch. 6 Conditionals

Section Table of Contents

Conditionals are basically when the computer checks if a certain condition and runs a certain chunk of code depending on if it’s true or not. This is important for your coding because it gives you much more control since it represents a real life situation where different paths might be taken depending on different factors.

The if statement

The simplest conditional is an if statement. The flow chart below summarizes how an if statement behaves in a program.

https://s3.amazonaws.com/thinkific/file_uploads/288722/images/213/45d/1af/1591256689594.jpg

The code statements inside of the if block are only executed if a given condition is met. You actually use if statements in your daily life:

Here is the general structure of an if statement:

if (condition) {
			// *if block code here*
}