mercredi 27 juin 2018

if statement evaluates as true but doesn't go into the code

i have this code in android project

for (int j = 0; j < chosenShoppingList.size(); j++) {
        if (_product.getProductID() - chosenShoppingList.get(j).getProductID() == 0) {
            isInList = true;
            break;
        }
    }

i see in debug mode that on one pass it evaluates as true but it just skip the code

when i try this

for (ShoppingListItem item: chosenShoppingList) {
        if (item.getProductID() == _product.getProductID()) {
            isInList = true;
            break;
        }
    }

all is good, i just want to understand what is the problem there

Aucun commentaire:

Enregistrer un commentaire