For instance, consider how "break" or "continue" inside the braces would work.
For instance, consider how "break" or "continue" inside the braces would work.
I agree that it would be very bad form to use "break" inside a block like that. But in the cases where this construct applies, it would still be bad form to break if the outer block had curly braces and indentation, because skipping the rest of a row isn't a natural operation in the sort of way that skipping the rest of a collection is.
for(y=0; y<ymax; y++)
printf("y=%i\n",y);
for(x=0; x<xmax; x++)
{
//...
}
And it will not work anymore as intended.Granted it's a small mistake and it will not take more than 5 minutes to fix, but it still add a small load to your already busy mind.
for(int y=0; y < ymax; y++)
...
and didn't shadow y from an enclosing scope, that would have given the compiler a chance to catch that error. for(i=0; i<imax; i++)
printf("i=%i\n",i)
{
//...
}
Which also compiles and which is wrong in the same way. I don't recall ever having made or having seen this.It's almost like everybody forgot about https://matt.sh/howto-c#_formatting already. :(
I'm not convinced. Even iterating over a 2D grid, one loop is iterating over the columns, and the other the rows, and indentation (and braces) can help see which is which.
The behaviour of 'break' might be confusing but then that's always the case in nested loops, no matter how you notate them.