Hot Posts

while and do…while loops

Form:

while(true/false){...}

The while loop is executed each time round so if the value to be tested is set here it will be reset every time round.

while( (x = getX()) != 0 )
{
...
}

If getX() returns an int then this loop will never finish.

do{...} while(true/false) 

Examples of valid do … while loops

do { break ; } while (true) ;
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: