Conditional Statements
Learn about conditional statements in Solidity.
We'll cover the following...
Conditional statements are used to do different actions based on certain conditions and are supported by Solidity. Here, we’ll go through the different conditional statements.
The if statement
The if statement enables Solidity to make judgments and carry out assertions conditionally. Here’s the syntax of the if statement:
Here’s a code example of a Solidity smart contract that demonstrates the use of the if statement:
Line 4: We establish a contract titled
ControlDemo.Lines 7–8: We declare two state variables,
firstandsecond, both classified asuint16. They’re initialized with the values20and30, respectively.Line 10: We define a function named
isFirstGreater()with thepublicvisibility specifier. It has the return typebool.Line 13: We declare a local variable named
resultof thebool...