Skip to Content
Mastering Blockchain - Second Edition
book

Mastering Blockchain - Second Edition

by Ankur Daharwal, Imran Bashir, Pranav Burnwal
March 2018
Beginner to intermediate
656 pages
20h 9m
English
Packt Publishing
Content preview from Mastering Blockchain - Second Edition

Control structures

Control structures available in solidity language are if...else, do, while, for, break, continue, and return. They work exactly the same as other languages such as C-language or JavaScript.

Some examples are shown here:

  • if: If x is equal to 0 then assign value 0 to y else assign 1 to z:
      if (x == 0) 
          y = 0; 
      else 
          z = 1; 
  • do: Increment x while z is greater than 1:
      do{ 
          x++; 
      } (while z>1); 
  • while: Increment z while x is greater than 0:
      while(x > 0){ 
          z++; 
      } 
  • for, break, and continue: Perform some work until x is less than or equal to 10. This for loop will run 10 times, if z is 5 then break the for loop:
      for(uint8 x=0; x<=10; x++) 
      { 
          //perform some work 
          z++ 
          if(z == 5) break; 
      } 

It will continue the work similarly, but ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Blockchain - Third Edition

Mastering Blockchain - Third Edition

Imran Bashir
Mastering Blockchain

Mastering Blockchain

Lorne Lantz, Daniel Cawrey
Mastering Ethereum

Mastering Ethereum

Andreas M. Antonopoulos, Gavin Wood

Publisher Resources

ISBN: 9781788839044Supplemental Content