Browsed by
Schlagwort: java

The while-else-loop

The while-else-loop

Sometimes, „while“ and „if“ are interchangeable, for example while if you are „iterating“ over a collection that will only contain one or zero elements. In Java, both constructs have the same syntax, so I often find myself switching from one to the other. Yesterday, I didn’t notice that my „if“ construct already had an „else“ branch, and so I created a while-else-loop. It took Eclipse like 10 seconds to realize that there’s something wrong, so when I saw my error…

Weiterlesen Weiterlesen