Programming-Idioms

History of Idiom 43 > diff from v10 to v11

Edit summary for version 11 :

Version 10

2015-08-18, 13:27:42

Version 11

2015-08-20, 10:38:32

Idiom #43 Break outer loop

Look for a negative value v in 2D integer matrix m. Print it and stop searching.

Idiom #43 Break outer loop

Look for a negative value v in 2D integer matrix m. Print it and stop searching.

Imports
#include <stdio.h>
Code
int i,j;
for(i=0;i<sizeof(m)/sizeof(*m);i++)
{
	for(j=0;j<sizeof(*m)/sizeof(**m);j++)
	{
		if(m[i][j]<0)
		{
			printf("%d\n",m[i][j]);
			goto end;
		}
	}
}
end:
Comments bubble
only works if m is allocated statically or on the stack, not if allocated in the heap.