If/Else Statements

Here’s one of the basic principles of programming, conditional statements.

Heres a break down of the structure for what an if statement looks like. When coding we have to come up with a logic flow that will get the program to do what we want it to.

The values true and false are boolean data types. They can only be one or the other and this is the basis of figuring out which block of code will be executed.

Here’s an example with some actual code to try and get a better example of whats going on. We have a number that is in a variable, we assign the number 5 to it.

The if statement then checks hm… is number (5) greater than 10? this equates to false so the code jumps to else and runs the code there.

This may seem very trivial but if statements and this logic is most likely used in every worthwhile program out there!

Leave a comment