Program does not run both For links within if - C

Asked

Viewed 187 times

1

I have 2 ties for within a if, as shown below:

              if (grid[j][k] == words[i][0]){ 
                    int el = j, col = k;
                    //Metodo direita, baixo
                    for(l=0;l < wordlen(search_word);l++){
                        if(l%2 != 0 ){
                            // Procura à direita
                            if(words[i][l] == grid[el][col]) {
                                matched[el][col] = 1;
                                col++;
                                if(words[i][l+1]=='\0') {
                                    break;
                                }
                            }
                        } else {
                            // Procura à baixo
                            if(words[i][l] == grid[el][col]) {
                                matched[el][col] = 1;
                                el++;
                                if(words[i][l+1]=='\0') {
                                    break;
                                }
                            }
                        }
                    }
                    //Metodo baixo, direita
                    for(l=0;l < wordlen(search_word);l++){
                        if(l%2 == 0){
                            // Procura à direita
                            if(words[i][l] == grid[el][col]) {
                                matched[el][col] = 1;
                                col++;
                                if(words[i][l+1]=='\0') {
                                    break;
                                }
                            }
                        } else {
                            // Procura à baixo
                            if(words[i][l] == grid[el][col]) {
                                matched[el][col] = 1;
                                el++;
                                if(words[i][l+1]=='\0') {
                                    break;
                                }
                            }
                        }
                    }   
                }

The intention would be for him to go through the 2 loops, but he only executes the first one. Does anyone know why?

  • 1

    Create a [mcve] so someone can help you, because you can’t test your code.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.