Java loops and iteration concept


public static boolean checkForJacket(String lst) {
for (int i = 0; i < lst.length; i++) {
if (lst[i] == “jacket”) {
return true;
return false;

public static void main(String args) {
String suitcase = {“shirt”, “jacket”, “pants”, “socks”};

why are we returning false in “checkForJacket” method ?

if the loop finished (meaning "jacket" was not found in the array),
then something still has to be returned;
false indicates "jacket" was not found,
return false;

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.