Until now compute was a formula. Now it can choose. An if runs a block only when a
condition is true; an else covers the opposite case.
The comparison operators produce true/false:
==equal,!=not equal<less,>greater,<=at most,>=at least
A very common trap: = means assign a value, while == means compare. Use == inside
conditions.
def solve(n):
if n % 2 == 0:
return "even"
else:
return "odd"
string solve(long long n) {
if (n % 2 == 0) return "even";
else return "odd";
}
That is the whole idea of branching: test a condition, take one path or the other, return the matching answer. Everything in this module is a combination of these two-way choices.