Listen, I love Ethereum, I think it’s cool as hell, I even wrote a book about it, what I really don’t like is the documentation ( that’s why I wrote the book 🤔 ?) for instance here’s all the documentation on control structures:
Most of the control structures from JavaScript are available in Solidity except for switch and goto. So there is: if, else, while, do, for, break, continue, return, ? :, with the usual semantics known from C or JavaScript.
I get it, most programmers don’t want to be told what a for loop is for the 200th time in their career, but I side on those that do want to see a minimal example on all these control structures, so here we are, let’s go one by one.
if else :
The hardest working control statement in the business if serves a conditional and can be used in contracts like so:
pragma solidity ^0.4.0;contract Conditional { uint refVal = 10; function isGreaterEqual(uint testVal) view public returns( bool ){
if(testVal >= refVal){
return true;
}
} }// isGreaterEqual(9)... false
// isGreaterEqual(10)... true
// isGreaterEqual(11)... true