Logo

Programming-Idioms

History of Idiom 43 > diff from v39 to v40

Edit summary for version 40 by _darkcha0s:
New Csharp implementation by user [darkcha0s]

Version 39

2019-09-26, 14:22:03

Version 40

2019-09-26, 15:33:53

Idiom #43 Break outer loop

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

Illustration

Idiom #43 Break outer loop

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

Illustration
Code
bool keepLooping = true;

for(int i = 0; i < m.length && keepLooping; i++)
{
	for(int j = 0; i < m[i].length && keepLooping; j++)
	{
		if(m[i][j] < 0)
		{
			Console.WriteLine(m[i][j]);
			keepLooping = false;
		}
	}
}
Comments bubble
Trying to avoid GOTO with this implementation.