From 23379e10614cccf9126fca09781a1d2dcdfede90 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 29 Oct 2017 13:28:42 +0000 Subject: Ensure each code snippet in the docs can be extracted for tests --- docs/control-structures.rst | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'docs/control-structures.rst') diff --git a/docs/control-structures.rst b/docs/control-structures.rst index 0497365b..371c5b92 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -363,15 +363,19 @@ As a result, the following code is illegal and cause the compiler to throw an er In addition to this, if a variable is declared, it will be initialized at the beginning of the function to its default value. As a result, the following code is legal, despite being poorly written:: - function foo() returns (uint) { - // baz is implicitly initialized as 0 - uint bar = 5; - if (true) { - bar += baz; - } else { - uint baz = 10;// never executes + pragma solidity ^0.4.0; + + contract C { + function foo() returns (uint) { + // baz is implicitly initialized as 0 + uint bar = 5; + if (true) { + bar += baz; + } else { + uint baz = 10;// never executes + } + return bar;// returns 5 } - return bar;// returns 5 } .. index:: ! exception, ! throw, ! assert, ! require, ! revert -- cgit