load help;

@[name]
dao.control
@[name]

@[title]
Control Structures
@[title]

@[name]
dao.control.if-else
@[name]

@[title]
If-else Conditional Control
@[title]

@[text]

@[subsection]
Definition
@[subsection]
@[code(syntax)]
ControlBlock ::= Statement | '{' [ StatementBlock ] '}'

IfElseStmt ::= 'if' '(' [ LocalVarDeclaration ';' ] Expression ')' ControlBlock
               { 'else' 'if' '(' [ LocalVarDeclaration ';' ] Expression  ')' ControlBlock }
			   [ 'else' ControlBlock ]
@[code(syntax)]

@[code(dao)]
a = 5
if( a > 1 ) io.writeln( 'a > 1' )

if( a > 2 )
	io.writeln( 'a > 2' )
else
	io.writeln( 'a <= 2' )

if( a < 3 )
	io.writeln( 'a < 3' )
else if( a < 4 )
	io.writeln( 'a < 4' )
else
	io.writeln( 'a >= 4' )
@[code(dao)]


@[text]





@[name]
dao.control.for
@[name]

@[title]
For Looping Control
@[title]

@[text]

@[subsection]
Definition
@[subsection]
@[code(syntax)]
CFor  ::= 'for' '(' [ LocalVarDeclaration ] ';' [ Expression ] ';' [ ExpressionList ] ')'
              ControlBlock

APFor ::= 'for' '(' [ 'var' ] Identifier '=' Expression ':' [ Expression ':' ] Expression ')'
              ControlBlock

ForIn ::= 'for' '(' [ 'var' ] Identifier 'in' Expression {';' Identifier 'in' Expression} ')'
              ControlBlock

ForStmt ::= APFor | CFor | ForIn
@[code(syntax)]


C-style for loops:
@[code(dao)]
for( i = 0;  i < 10;  ++i ) io.writeln( i );

for( var i = 0;  i < 10;  ++i ) io.writeln( i );

for( var i, j = 0;  i < 10;  ++i, j+=2 ) io.writeln( i, j );

for( i, j = 0, k = 3;  i < 10;  ++i, j+=2 ) io.writeln( i, j, k );
@[code(dao)]


Arithmetic progression for loops:
@[code(dao)]
for( i = 1 : 10 ) io.writeln( i )

for( var i = 1 : 10 ) io.writeln( i )
@[code(dao)]


For-in loops:
@[code(dao)]
m = { 'def' => 123, 'cdf' => 789, 'abc' => 345 }

for( kv in m ) io.writeln( kv )

for( k in m.keys(); v in m.values() ) io.writeln( kv )

for( var k in m.keys(); v in m.values() ) io.writeln( kv )
@[code(dao)]


@[text]





@[name]
dao.control.while
@[name]

@[title]
While Looping Control
@[title]

@[text]

@[subsection]
Definition
@[subsection]
@[code(syntax)]
WhileStmt ::= 'while' '(' [ LocalVarDeclaration ';' ] Expression ')' ControlBlock
@[code(syntax)]

@[code(dao)]
i = 0
while( i < 10 ) i += 1
@[code(dao)]


@[text]





@[name]
dao.control.do-while
@[name]

@[title]
Do-while Looping Control
@[title]

@[text]

@[subsection]
Definition
@[subsection]
@[code(syntax)]
DoWhileStmt ::= 'do' ControlBlock 'while' '(' Expression ')'
@[code(syntax)]

@[code(dao)]
i = 0
do
	i += 1
while( i < 10 )

do {
	i += 1
	io.writeln( i )
} while( i < 15 )
@[code(dao)]


@[text]





@[name]
dao.control.switch-case
@[name]

@[title]
Switch-case Control
@[title]

@[text]

@[subsection]
Definition
@[subsection]
@[code(syntax)]
SwitchCaseStmt ::= 'switch' '(' Expression ')' '{'
                   { 'case' Expression [ ( ',' | '...' ) Expression ] ':' ControlBlock }
				   [ 'default' ':' ControlBlock ]
                   '}'
@[code(syntax)]
@[comment]
ConstExpressioin for case
@[comment]

@[code(dao)]
switch( 2 ){
case 0 : io.writeln( 'case 0' )
case 1 : io.writeln( 'case 1' )
case 2 : io.writeln( 'case 2' )
default: io.writeln( 'default' )
}
@[code(dao)]


@[text]
