Expressions and Control Structures

Taking decisions in code is an important aspect of a programming language, and Solidity should also be able to execute different instructions based on circumstances. Solidity provides the if...else and switch statements for this purpose. It is also important to loop through multiple items and Solidity provides multiple constructs such as for loops and while statements for this purpose. In this chapter, we will discuss in detail the programming constructs that help you take decisions and loop through a set of values.

This chapter covers the following topics:

  • Expressions
  • The if...else statement
  • The while statement
  • The for loop
  • The break and continue keywords
  • The return statement

Get Solidity Programming Essentials 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.