0

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?

Dustin Cook
  • 1,215
  • 5
  • 26
  • 44
  • possible duplicate of [I want to know the behaviour of break statement in C. Does it work only for ';for-while-do-switch' or also for 'if-statements'?](http://stackoverflow.com/questions/2565659/i-want-to-know-the-behaviour-of-break-statement-in-c-does-it-work-only-for-fo) – Lee Duhem Feb 28 '14 at 07:59

2 Answers2

6

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.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
3

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

Seidr
  • 4,946
  • 3
  • 27
  • 39