forelse
The construct was placed to accomodate for the case where there was zero iterations in a for loop. This is quite handy in web scenarios, for instance when you need to present a list, and the list is empty. You would then do something like this:
It's not by accidence that I show it like java code. I sometimes come across this scenario, but usually see it inside an if:
for (SearchItem item : items) {
... (do something with item)
} else {
.. (do something when there are no items)
}
And I have actually begun to find it too verbose :-)
if (!items.isEmpty()) {
for (SearchItem item : items) {
... (Do something with item)
}
} else {
... (Do something when there are no items)
}
So, +1 for a forelse construction..
0 comments:
Post a Comment