Share:
Notifications
Clear all

Earn While Learning Web3 Programming>> Start Here FREE!!!

[Solved] Control Flow If Statement In Solidity

2 Posts
1 Users
2 Reactions
486 Views
1
Topic starter

What Is Control Flow In Solidity?

 

 

NOTE:

This Is An Exercise From Our FREE Smart Contract Development With Solidity For Beginners Course (If you have not enrolled yet, you can join the course totally for FREE).

1 Answer
1
Topic starter

Control flow in solidity is the process of controlling the smart contract process flow with things like If statement, if else statement or if else if else statement.

here is an example of control flow if else statement in a solidity smart contract:

 

pragma solidity 0.8.7;

contract controlFlow {

 

          //state variable

          uint code1 = 5; //represent logged out or not logged in

          uint code2 = 10; //represents logged in

 

          //function to access content if user logged in using if else if else statement

          function userOnlyContent(uint _userAccessCode) public view returns(string memory) {

                    if (_userCode == code1) {

                          return "Not Logged In - Content Hidden";

                   }else if (_usercode == code2) {

                          return "Earn To Learn Web3 Programming With Free Courses at dprogramminguniversity.com";

                   }else {

                          return "Unidentified User Access Code - Try Again!";

                   }

          }

 

 

}

Solomon Foskaay Solomon Foskaay Topic starter 24/10/2021 8:24 am

if you run the above in REMIX IDE, you will get a button with input box that deny or give access to the info based on user inputted code in the input box. TRY IT and comment your experience below here.

Share: