Iam wondering about the best way to prevent accessing to multiple loops in a scalable way
String token;
ArrayList numbers;
ArrayList names;
for(String n : numbers){
if(token.equals(n)){
break;
}
}
for(String n : names){
if(token.equals(n)){
break;
}
}
I want to skip accessing the 2nd loop if i found a hit on the first one but i want to do it in a scalable way because maybe later i will have 5 lists
Solutions that i thought about
Make multiple returns inside the loops, but this is not a good programming technique
Set a flag and use it in the other loops(either by if condition or put it in the loop condition, but when we have 5 different lists, it means i will have 5 flags and checks on the loop before me.
I would appreciate your suggestions. Thank you