Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 26th, 2005, 12:25 AM   #1
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
I don't get it

If I write this code(which outputs the numbers 1 to 10 and each number's square) it runs fine:

int counter = 1;

do
{
cout << counter << "\t" << counter * counter << endl;
}while(++counter <= 10)

As I said above it outputs 1 to 10 and each numbers square. But if I change the way I increment the control variable to counter++ so it looks like this:

int counter = 1;

do
{
cout << counter << "\t" << counter * counter << endl;
}while(counter++ <= 10)

It actually outputs all numbers plus and including 11 and it's square. I don't understand why that is. It seems to me that it shouldn't matter because either way when 10 gets incremented to 11 it should cause the test condition to fail, meaning the last number output should still be 10.

Please explain what's goin on here. I'm just a beginner(again).
357mag is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC