Vocab

algorithm - A set of instructions that accomplish a task.
selection - The process that determines which parts of an algoritm is being executed based on a condition that is true or false.

What is a conditional?

A conditional is a statement that affects the flow/outcome of a program by executing different statements based on the result of a true or false statement. That true or false statement is a boolean expression.

Conditionals appear in almost every programming language because of how important it is for changing the flow of the program.

Conditionals statements are used by the selection process for a program.

Question: What statement most commonly fills the role of a conditional in almost all programming languages?

If/Else Statements

In almost every programming language, if/else statements fill in the role of the conditional. Some languages call this switch blocks but if/else is the most used term.

If/Else Statement Example:

number = 3          # value that will affect true or false statement
if number == 5:     # if part determines if the statement is true or false compared to another part of the program
    print("yes, 5 does equal 5")
else:               #else part only executes if the if part is false
    print("no, " + str(number) + " does not equal 5")
no, 3 does not equal 5

If/Else Statements can also just be if statements. This can be used more as an interruption rather then yes or no response.

If Statement Example:

progress = 0
while progress < 100:
    print(str(progress) + "%")
    
    if progress == 50:
        print("Half way there")

    progress = progress + 10
print("100%" + " Complete")
    
0%
10%
20%
30%
40%
50%
Half way there
60%
70%
80%
90%
100% Complete