Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 java help - Loop Application
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
comp_help




PostPosted: Wed Nov 18, 2009 11:07 pm   Post subject: java help - Loop Application

Can someone please explain this question because I don't understand it:

For what kind of looping situations is a 'do' usually preferable to 'while'?

I am new to Java, so please try to keep it as simple as possible. Thanks.
Sponsor
Sponsor
Sponsor
sponsor
Superskull85




PostPosted: Thu Nov 19, 2009 12:06 am   Post subject: RE:java help - Loop Application

In a while (condition){...} loop the condition is always checked at the beginning of the loop. This kind of loop does not assure the programmer that it will run at least once (if the condition is false on the first check the loop will never execute).

In a do{...}while (condition) loop the condition is always checked at the end of a loop. This kind of loop does assure the programmer that it will run at least once (the loop will run, and than if condition is false the loop will exit).

Given that information can you think of a situation where you would want a loop to execute at least once?
comp_help




PostPosted: Sat Nov 21, 2009 3:22 pm   Post subject: RE:java help - Loop Application

Thanks for the explanation Superskull85.

I got: If a correct user input is required within the loop, then it?s best to use do-while loop, since it checks the condition in the end, meaning that the loop is run at least once.

Thanks anyways.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: