You are on page 1of 1

School of Computer Science &

Loops
Information Technology
A block of code is repeated
A pre-defined number of times
G6DICP - Lecture 5  Untila certain (boolean) condition is met
 Determinate vs indeterminate

 The contents of variables often change in


Control Structures each cycle.
 Beware of perpetual loops!

For Loops While Loops


 Probably the most common type of loop.
while (continuing condition)
for ( starting condition;
continuing condition;
change each cycle )
while (a<=10)
{
for ( a=1; a<=10; a++ ) ...
{ }
...
}

3 4

Do.. while Loops Switch


switch (answer)
do { {
case ‘y’ : { ... }
... case ‘n’ : { ... }
} while (continuing condition) default : { ... }
}

do { switch (answer)
... {
case ‘y’ : { ... }; break;
} while (a<=10) case ‘n’ : { ... }; break;
default : { ... }; break;
5 6
}

You might also like