Is there a cleaner way than while (1) ... break;?
java
Solution
Firstly, `while(1)` is invalid in Java. You'd need `while(true)`. Personally I tend to handle this as:
String line;
while ((line = reader.readLine()) != null && TreeIterator.hasNext())
{
...
}
Although I don't normally like side-effects in conditions, this "get the next one and check it actually exists" approach is sufficiently common that the normal readability pains aren't a problem IME.
Problem
This application matches two lists of words, one in a dictionary file, one that is generated by the application in a TreeSet. Maybe there are better ways to do this, but it's outside of the scope of this question - the way that we use is to read one line from the file, one line from the TreeSet, compare them and save if the TreeSet line equals the file line read a line from the file if the TreeSet line > file line read a line from the TreeSet if the file line > TreeSet line In pseudo code: ``` while (1) { String dict = reader.readLine(); if (dict == null || !TreeIterator.hasNext()) break; if (dict.equals(TreeIterator.next())...save elseif > .... read tree elseif < .... read file } ``` It doesn't seem correct to use while (1), but I didn't find a cleaner way to express this double condition. There is no way to read the two strings inside the while's condition, is there? Is it possible to maintain the simplicity of this approach (no more clutter), while losing the strange while(1)? Best regards.