Loops/Nested: Difference between revisions

Line 388:
// loops nested
Enumerable.Range(0, 10).Any( k => Enumerable.Range(0, 10).Any( l => { Console.Write(" {0}", a[k, l]); return a[k, l] == 20; }));
}
}</lang>
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
 
namespace Nest
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[10, 10];
Random r = new Random();
 
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
a[i, j] = r.Next(0, 20) + 1;
}
}
 
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
Console.Write(" {0}", a[i, j]);
if (a[i, j] == 20)
{
goto Done;
}
}
Console.WriteLine();
}
Done:
 
Enumerable.Range(0, 10).Any( k => Enumerable.Range(0, 10).Any( l => { Console.Write(" {0}", a[k, l]); return a[k, l] == 20; }));
}
}
}</lang>
Anonymous user