[Gllug] Somewhat OT - (GNU) C++

Dan Kolb gllug at eco.li
Mon May 24 14:55:23 UTC 2010


On Mon, May 24, 2010 at 03:53:46PM +0100, Adrian McMenamin wrote:
> On Mon, 2010-05-24 at 15:50 +0100, Dan Kolb wrote:
> > On Mon, May 24, 2010 at 03:47:08PM +0100, Adrian McMenamin wrote:
> > > Am I losing my marbles or is GNU g++ broken when this code:
> > > 
> > > #include <iostream>
> > > using namespace std;
> > > 
> > > int main()
> > > {        
> > >          for (int x = 90; x > 20; x--)
> > >          {       cout << x << " ";
> > >          }
> > > }
> > > 
> > > outputs integers in reverse order from 90 to 21??
> > 
> > What do you think it should do? It looks like it's designed to output the
> > numbers 90 down to 21....
> > 
> I don't think the loop should execute at all. The condition x > 20 being
> met from the very first iteration.
> 
> Maybe I ave just misunderstood this...

You have. The loop will run while the second condition is true. Once it becomes
false (i.e. x = 20), the loop terminates.

Dan
-- 
Immigration is the sincerest form of flattery.
		-- Jack Paar
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list