In the conventional loop, we could have as below, making single nested layer.
for (int i=0; listObject != null && i < listObject.size(); i++) {
// Do whatever we want
}
However, using the below style for each loop, I'll need a double nested code: -
if (listObject != null) {
for (Object object: listObject) {
// Do whatever we want
}
}
Is it possible to embed the listObject != null
condition into the for-loop statement to make it single nested code?