Solidity Series

Solidity Programming Language – If-else

In Solidity, if-else statement for conditional execution of code.

Here’s a basic example:

In this example, the checkNumber function takes an input _input and sets the num variable based on the condition. If _input is greater than 10, num is set to 1; otherwise, it is set to 2.

Solidity also supports additional conditional constructs, such as the ternary operator. Here’s an example:

In this example, the ternary operator (_input > 10) ? 1 : 2 is used to achieve the same result as the if-else statement. If _input is greater than 10, num is set to 1; otherwise, it is set to 2.

Remember to check the Solidity version specified in the pragma statement, as newer versions may have changes in syntax or features.

Code:

Hi, I’m saksham dixit

Leave a Reply

Your email address will not be published. Required fields are marked *