To rise above the label of calculator, a programming language must have conditional statements and loops.
A conditional statement is a statement that may or may not execute, depending on the circumstances.
A loop is a statement that gets repeated multiple times.
If, Then, Else
The most basic conditional statement is the
if statement
. It executes some code only if a given condition is true. It is the same in all languages covered in this book. For example:
1 if (vampire) { // vampire is a boolean
2 useWoodenStake();
3 }
Curly brackets ({}) define a block of code (in Java, Scala, ...