mardi 27 janvier 2015

How can I make and ELSE clause outside a FOR loop, for an IF clause inside the FOR loop?


for (int i = 0; i < array.size(); i++) {
if (array.get(i) == SEARCH_VARIABLE) {
booleanValue = true;
} else {
booleanValue = false;
}
}


I'm not sure if the title is very coherent, so I'll explain. What I need is to search for an element inside an array. If the element is found, I set a boolean variable to true, otherwise, it must be false. On the above code snippet, if I find the element anywhere but on the last position, my boolean variable will came out as "false". How can I put the else clause after all iterations of the FOR loop have been made ?


Aucun commentaire:

Enregistrer un commentaire