//please can someone explain the output 4 8 12,why is it so? Thanks
int count = 0;
do
{
for( int i = 0; i < 4; i++ )
count++;
cout << count << ‘ ‘;
} while ( count < 10 );
PulsarScript 0 Junior Poster
Recommended Answers
Jump to PostThis is your code.
int count = 0; do { for( int i = 0; i < 4; i++ ) { count++; } cout << count << ‘ ‘; } while ( count < 10 );
What's not clear about this?
Jump to PostThe for loop runs four iterations, so count gets incremented by one four times. count goes from 0 to 1 to 2 to 3 to 4, then is displayed. The while condition is still true, so the for loop executes again: 5,6,7,8, display.
While condition still true, so for loop …
All 8 Replies

111100/11000

111100/11000

111100/11000
PulsarScript 0 Junior Poster
Moschops 683 Practically a Master Poster Featured Poster
PulsarScript 0 Junior Poster
vmanes 1,165 Posting Virtuoso
PulsarScript 0 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.