Control Flow Methods
Control flow is a general term that denotes any programming syntax that can redirect the execution of a program. Control flow methods in general are what allow programs to be dynamic in their execution and computation: depending on the current state of a program or its input, the execution of that program and thus its output will dynamically change.
if Statements
The most common form of control flow in any programming language is conditionals, or if
statements. if
statements are used to check for a specific condition about the current state of the program and, depending on the result (whether the condition is true or false), the program will execute different sets of instructions.
In Python, the syntax of an if
statement is as follows:
if [condition to check]: Â Â Â Â [instruction set to execute if condition is true]
Given the readability of Python, you can probably already guess how conditionals work: when the execution of a given...