Dustin Cook
Dustin Cook

Reputation: 1305

While Loops with Two IF Statements

I have a script that reads in a file using a while loop. One IF statement reads the line (it is a csv file) then a second checks for a match.

while ( file != NULL )
{
    if ( sscanf to read the line )
    {
        if ( to check for matches)
        {
            toggle variable
            break;
        }
    }
}

If I add the break into the second IF statement (as above) will that break out of the two IF statements and the WHILE loop? Or do I need additional break; to get out of thw while loop?

Upvotes: 0

Views: 274

Answers (2)

Some programmer dude
Some programmer dude

Reputation: 409442

A break or continue statement is for the nearest loop. The if statements are not even considered.

The exception of course being break within a switch statement.

Upvotes: 6

Seidr
Seidr

Reputation: 4936

Any break within a while loop will break out of that loop. break ignores if statements.

Upvotes: 3

Related Questions