Originally Posted by
Sipher
Nice trick. But remember that it's a good programming practice to not change the value of counters inside the loops.
Like most things described as "good practice", there are multiple views on what "good" really means.
A technique, if you want to avoid changing counters inside their loops, is
Code:
for(i = 0, barrel_on = true; barrel_on && i <10; i++)
{
for(j = 0; barrel_on && j <cols; j++)
{
scanf("%d", &matrix[i][j]);
if(isalpha(matrix[i][j])) barrel_on = false;
}
}
Or (at the risk of encouraging cries of horror from the "goto is evil" crowd)
Code:
for(i = 0; i <10; i++)
{
for(j = 0; j <cols; j++)
{
scanf("%d", &matrix[i][j]);
if(isalpha(matrix[i][j])) goto break_out;
}
}
break_out: