does continue work in a do while?

mrblah picture mrblah · Jan 6, 2010 · Viewed 29.6k times · Source

I have a do while that looks like:

User user = userDao.Get(1);

do
{
 // processing


 // get the next user
 //
 user = UserDao.GetNext(user.Id);

 if(user == null)
       continue;   // will this work?????????????
}
while ( user != null)

If it does work, its going to go to the top of the do statement, and user is null so things are going to break?

Maybe I should rework the loop to a while statement?

Answer

helios picture helios · Jan 6, 2010

The continue makes it jump to the evaluation at the botton so the program can evaluate if it has to continue with another iteration or exit. In this case it will exit.

This is the specification: http://java.sun.com/docs/books/jls/third_edition/html/statements.html#6045

Such language questions you can search it in the Java Language Specification: http://java.sun.com/docs/books/jls/