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

Adrian McMenamin adrian at newgolddream.dyndns.info
Mon May 24 14:53:46 UTC 2010


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...

It's a simplified fragment of code to explore an odd result - not
something in production!

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list