You are on page 1of 12

Conditionals, Loops

Conditionals allow a program to make decisions about which lines of code run and which do not. They let actions take place only when a specifi c condition is met. Conditionals allow a program to behave differently depending on the values of their variables.

loop is a repetition of statements. !t allows statements to be defined, modified, or e"ecuted repeatedly until a termination condition is met.

The parentheses associated with the for (init; test; update) structure enclose three { statements# init, test, and update. statements The statements inside } the block are run continuously while the test evaluates to true. The init portion assigns the initial value of the variable used in the test. The update is used to modify the variable after each iteration

for structure runs in the following se$uence# %. The init statement is run &. The test is evaluated to true or false '. !f the test is true, continue to step . !f the test is false, "ump to step # (. )un the statements within the block *. )un the update statement and "ump to step $ +. ,"it the structure and continue running the program

Original Code
si-e.&//, &//01 line.&/, &/, &/, %2/01 line.'/, &/, '/, %2/01 line.(/, &/, (/, %2/01 line.*/, &/, */, %2/01 line.+/, &/, +/, %2/01 line.3/, &/, 3/, %2/01 line.2/, &/, 2/, %2/01 line.4/, &/, 4/, %2/01 line.%//, &/, %//, %2/01 line.%%/, &/, %%/, %2/01 line.%&/, &/, %&/, %2/01 line.%'/, &/, %'/, %2/01 line.%(/, &/, %(/, %2/01

Code expressed using a for structure

si-e.&//, &//01 for .int i 5 &/1 i 6 %*/1 i 75 %/0 8 line.i, &/, i, %2/01 9

:ested Loop
The for structure produces repetitions in one dimension. :esting one of these structures into another compounds their effect, creating iteration in two dimensions. This techni$ue is useful for creating diverse patterns and effects. The numbers produced by embedding iterative elements can be applied to color, position, si-e, transparency, and any other visual attribute.