if
elif
else
for
while
break
continue
truthy
value is a value that translates to true
in the case of conditional statements like if
and while
.falsey
value is a value that translates to false
in the same situations.falsey
value is anything that is empty or represents nothing, which includes;0
false
'' # empty string
[] # empty list
() # empty tuple
{} # empty set or dict (depends on type decl)
null
truthy
if it is not one of the above values.if
statement.elif
(else if) statements, and can also optionally be concluded with an else
statement.if
and elif
statements take an expression, which is evaluated to be truthy
or falsey
. If the expression for the statement evaluates as truthy
, the contents of the following block are run. If not, the next elif
statement (if any) is run, which also takes an expression. If none of the elif
statements' expressions evaluate to a truthy value, the else
block (if any) will be run.if
statements can be used as part of assignment statements, like the following;conditional expressions
instead of statements, due to the difference in definition between a statement and an expression.for
and while
.for
loops are used when the number of repetitions are known in advance, e.g. to do something 5 times, you can use the following code;while
loops are used when you don't know the amount of repetitions that will need to be done, e.g. when you're reading lines from a file and you don't know how many lines are in the file.while
loops take an expression, and if it evaluates to a truthy
value, the block of the loop will be run.break
and continue
.break
when used inside a loop will stop the execution of the loop and continue execution of the program after the block of the loop.continue
when used will stop the execution of the current loop and continue from the next loop.