• Post Reply Bookmark Topic Watch Topic
  • New Topic

While loop that contains no body, just a method for a condition.  RSS feed

 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I'm writing a program that solves sudokus. First I'll show you the code I have a question about.






The while loop in the solve method has no body. It just runs until the method checkForSolvedSquares returns false. This method orginally did not return a boolean condition and was just void. I changed it to return a boolean because that seems to work well with letting the solved() method know when it can continue. There will be lots of methods like this in the solved method and the solved method will probably loop until the sudoku is solved. At the moment my program solves easy sudokus but I have yet to add more methods to solve complicated ones.

My question is - Is it bad programming practice to just have a while loop like that without anything in it?

I've noticed some boolean methods in the API do not have typical boolean method names, like this method doesn't. Is my method name bad programming practice? Or is this acceptable sometimes, like when the method does more than just ask a true or false question?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neil Cartmell wrote:My question is - Is it bad programming practice to just have a while loop like that without anything in it?

I think so. You don't need to put code in the loop body, a comment about why there is no body and that the method will eventually return false will do:
 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thank you very much for replying.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!