Chapter 5: 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
statement 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 will help you make decisions and loop through a set of values. The goal of this chapter is to understand the programming constructs and expressions available in Solidity, helping you to write functional smart contracts with loops and conditional statements.
This chapter covers the following topics:
- Understanding Solidity expressions
- The
if...else
statement - Exploring the
while
loop - Understanding the
for
loop - Understanding the
do while
loop - Understanding the
break...