© Carlo Milanesi 2018
Carlo MilanesiBeginning Rusthttps://doi.org/10.1007/978-1-4842-3468-6_4

4. Controlling Execution Flow

Carlo Milanesi1 
(1)
Bergamo, Italy
 
In this chapter, you will learn:
  • How to use if statements to execute different statements based on a Boolean condition

  • How to use if expressions to generate different values based on a Boolean condition

  • How to use while statements to repeat some statements as long as a Boolean condition holds

  • How to use for statements to repeat some statements for a definite number of times

  • What is the scope of validity of variables

Conditional Statements (if)

The main usage of Boolean values is in making decisions about how to let the execution of the program proceed. Suppose you want to print a word, but only ...

Get Beginning Rust: From Novice to Professional 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.