05.05.2014 Views

csmstr - Omega Engineering

csmstr - Omega Engineering

csmstr - Omega Engineering

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

NOTES FOR EDICT USERS<br />

CRIMSON USER MANUAL - MODULAR CONTROLLER<br />

You will notice that the for statement contains three distinct elements, each separated by<br />

semicolons. The first element is the initialization step, which is performed once when the loop<br />

first begins; the next is the condition, which is tested at the start of each loop iteration to see if<br />

the loop should continue; the final element is the induction step, which is used to make a<br />

change to the control variable to move the loop on to its next iteration. Again, remember that<br />

if you want more than one action to be included in the loop, include them in curly-brackets!<br />

THE DO LOOP<br />

This type of loop is similar to the while loop, except that the condition is tested at the end of<br />

the loop. This means that the loop will always execute at least once.<br />

The architecture of the do loop statement is as follow…<br />

do {<br />

action1;<br />

} while ( condition );<br />

The example below shows the example from above, rewritten to use a do loop…<br />

int i:=0, t:=0;<br />

do {<br />

t += Data[i];<br />

} while( ++i < 10 );<br />

return t;<br />

LOOP CONTROL<br />

Two additional statements can be used within loops. The break statement can be used to<br />

terminate the loop early, while the continue statement can be used to skip the balance of the<br />

loop body and begin another iteration without executing any further code. To make any sense,<br />

these statements must be used with if statements to make their execution conditional. The<br />

example below shows a loop that terminates early if another program returns true…<br />

for( i:=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!