5    Conditional Statements and Loops

After reading this lesson, you’ll be able to:

  • Control the execution of your code using an if…else statement.
  • Iterate through instructions using while and for loops

In lesson 4, you have learned how to define values and variables to store the results of some computation. But life is not always so linear: when performing a task, you may also need to make informed decisions by selecting one approach rather than the other. In this lesson, you’ll discover how to combine different executions of your code through given conditions. You’ll learn how to use the most common conditional statements and loops in Scala. In the capstone, you’ll use if…else statements to check if the system should allow a requested operation.

5.1           If…else statement

5.2           While Loop

5.3           For Loop

5.4           Summary

5.5           Answers to quick checks