Is it safe to use break inside list_for_each_entry?

c, linux-kernel

Solution

`break` always breaks out of only the innermost loop, so the outer loop is not affected. In fact, to break out of multiple levels of loops, you have to use `goto`.

Problem

Is it safe to use a break instruction for a `while/for` loop, which is inside a `list_for_each_entry` instruction (in the Linux kernel)? By example: ``` list_for_each_entry(obj1, vars, list) { ... while(j < k) { ... if(k >= MAX_ITERATIONS) break; // break the while ... } ... } ``` Will the while loop be broken as expected or will the `list_for_each_entry` be broken?

Original source