简体   繁体   中英

Executing for loop inside if statement

I can't figure it out why my program won't start executing the for loop: the logic for the for loop is correct, but when the program runs it just skips the for loop, without executing it. If i is equal to count , it should read last remaining elements from array called se and write to array finallyDone .

while(check && i < len){
    int fi = first[i];
    int se = second[j];
    if(fi < se){
        finallyDone[count] = fi;
        i++;
    }
    else{
        finallyDone[count] = se;
        j++;
    }
    int l;
    if(i >= len){
        for(l = count; l < len * 2 - count; l++){
            finallyDone[count + 1] = se;
        }
        check = false;
    }
    count++;
}

This is where it goes wrong:

while(check && i < len){
   //and later
    if(i >= len){

You can only walk to the IF-statement if i is smaller than len , but you will only walk into the IF-statement if i is equal to len or bigger. Those two statements are contradictory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM