© Adam L. Davis 2020
A. L. DavisModern Programming Made Easyhttps://doi.org/10.1007/978-1-4842-5569-8_6

6. Conditionals and Loops

Adam L. Davis1 
(1)
Oviedo, FL, USA
 

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, ...

Get Modern Programming Made Easy: Using Java, Scala, Groovy, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.