Category: Control Flow

Functions and Subroutines

A function or subroutine is a way to separate sections of code which allows us to organise our code and execute the code multiple times with slight variations and differences. Different programming languages have different words for this; functions, subroutines, methods, etc. They will effectively mean the same thing and…

Continue Reading Functions and Subroutines

Case and Switch Statement

Case and switch statements are used to run conditional code based on the state of another variable. This differs from if statements, as case statements cannot use less than or more than operators, only equals operators. Case statements are used only when a variable is equal to certain state. Think…

Continue Reading Case and Switch Statement

While and Do While Loops

A while loop is a way of repeating a section of code while a condition is true. While loops have two main parts; the condition and the code that will be repeated and executed. A while loop is similar to a for loop, all for loops can be represented as…

Continue Reading While and Do While Loops

For Loops

A for loop allows us to repeat sections of code for a specified number of times, or iterations. There are 4 components that make up a for loop; the iterator, the condition, the increment and the code to be executed. A for loop will repeat code for a specific number…

Continue Reading For Loops

If and Else If Statements

If statements allow us to add conditional code to be executed based on certain conditions, this means we can add different routes or paths in our code. With if statements you can also add additional routes by using else if statements and else blocks of code. You can add as…

Continue Reading If and Else If Statements