• 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

loop condition query

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,

Pls hel me in this.

suppose-
there is a code somewhat like this

int i=5;
do{
//some code here
}
while (i<5)

what will the condition 5<5 in while loop turn out to be. True or false??
If I am not wrong this should give FALSE.

Just getting confused.. pls tell me

thx
megha
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you are using the do/while loop construct, the loop will execute at least once before checking the looping condition. In this case, since i=5 and your loop condition is i<5, the loop will execute once and then continue on with the remaining code. If you had chosen to use the while loop construct, the loop would not have executed at all sinc ethe looping condition is checked before the loop code is executed.
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what ever be the condition, be it in while loop or any thing else 5 < 5 is always false.
[ June 28, 2004: Message edited by: Sanyev Babu ]
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

5 < 5 is always wrong



i think you mean "false". there is nothing wrong with the statement '5 < 5' or any version thereof. it is a perfectly valid statement, it just evaluates to false.
[ June 28, 2004: Message edited by: fred rosenberger ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic