• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Confusion again???

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

Consider the code below,



What is the result?

When run, it prints 0 through 9, but I feel that it enters an infinite loop?? bceause the ternary operator always assignes true to the flag in the statement while ( (flag)? true:false )...........Anyone on this???

Thanks in advance.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

no,
while((flag)?true:false)
this assigns nothing to the flag. It just returns true, when flag is true and false when flag is false.
It's just the same as if you simple coded
while(flag);

By the way, the continue does nothing here, it just jumps to the while clause.


Yours,
Bu.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bu,

I understand it now. If any of fellow ranchers come across questions like this elsewhere, please post them here. That would be helpful for people like me.

Thanks all.
 
reply
    Bookmark Topic Watch Topic
  • New Topic