mardi 15 décembre 2020

How can i create an if statement within a for loop that breaks the for loop in c?

I'm working on some code in C. I'm trying to create a for loop with an if statement inside of it. And I want this if statement to break the for loop.

        for(int i = 0; i != n; i++){
            if(dashes[i] == '-'){
                break;
            }
            stillPlaying = 2;
        } 

Basically, i want the program to check the array "dashes" if it finds a dash, it breaks the for loop and continues with the rest of the code. If it doesn't find a dash, the for loop is broken and stillPlaying is set to 2. Is there a way to do this?

Aucun commentaire:

Enregistrer un commentaire