I have a for loop in a java program which iterates through a set of maps.
Inside the loop I have around 10 different if-statements which checks the name of each key
If you want the current iteration to end after the first condition evaluates to true, you should use if-else-if-...-else
. In my opinion, that's more clear than using continue
, since that's what this syntax exists for.
for ( map : object.entrySet()) {
if (map.getKey().equals.("something") {
do_something;
}
else if (map.getKey().equals.("something_else") {
do_something_else;
}
else if (...) {
...
}
... else {
...
}
}