mercredi 8 septembre 2021

Compounded control statement does not function properly

A self-written method in my android application consists of a rather compounded control statement:

private int getNextIndex() {
    int output = 0;
    int relativeIndex;
    Boolean foundActive = false;
    int size = lessonList.size();                                                               
    for (int i = 1; i <= (size - currentIndex - 1); i++) {
         if (lessonList.get(currentIndex + i).getActive()) {
             output = currentIndex + i;
             foundActive = true;                                                                
             break;
         }
    }
                                                                                       
    if (foundActive = false) {                                                                  
        for (int j = 0; j < currentIndex; j++) {
             if (lessonList.get(j).getActive()) {
                    output = j;
                    foundActive = true;
                    break;
             }
        }
    }                                                                                                    

    if (foundActive = false){
           output = currentIndex;
    }

    return output;
}

Unfortunately, for reasons unclear to me the second, conditional loop is never executed, even if the first loop did not use the "break" statement (and therefore "foundActive" is still equal to "false"). I haven't tested if the third condition is ever reached, but have good reason to believe it isn't.

Aucun commentaire:

Enregistrer un commentaire