0

What the diffrent bettween while looping, conter-controlled while loop, sentinel-controlled while loop,flag-controlled while loop, do while loop and For loop.
when we use each one of them???

please, explean in detileas.
thanx
:)

5
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by firstPerson
0

What the diffrent bettween while looping, conter-controlled while loop, sentinel-controlled while loop,flag-controlled while loop, do while loop and For loop.
when we use each one of them???

A for loop tends to lend itself to things which need to be done x number of times:

for ( i = 0; i < x; ++i ) { /* ... */ }

A while loop tends to lend itself to doing things while a condition is true, such as reading lines from a file (while there are lines to read):

while ( getline(file, line) ) { /* ... */ }

A do...while loop presents itself as a good choice for a loop that must iterate at least once (even if the loop condition is 0, the loop body will execute):

do { /* prompt() */ } while ( respond() );

Other situations present themselves for mix-and-match and programmer preference. YMMV.

0

"What the diffrent bettween while looping, conter-controlled while loop, sentinel-controlled while loop,flag-controlled while loop, do while loop and For loop. "

Their syntax and spelling:)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.