From the course: Blockchain: Learning Solidity

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Conditionals in Solidity

Conditionals in Solidity

- [Instructor] If you have experience in other languages this will be the easiest part to learn, as Solidity has your typical conditionals: if, for loop, et cetera. The only conditional not available that you may have seen in other languages are switch statements and go to. So let's explore a few. Again, I'm going to clean my screen right here and then I will start with an if statement. (keyboard clicks) And it's very familiar to JavaScript people or any other programming language, it's very, very familiar. So let's say if a equals 2, execute the statement, "execute this code," else, then "execute this code." So if this is true, so if a equals 2, then it will execute this code here. Otherwise execute this code, as simple as this. The next one is for checking the condition first. (keyboard clicks) So basically while, so if you're familiar with while, same thing. If a is larger or equal to zero, then, "execute this…

Contents