List comprehensions: Difference between revisions

→‎C# Iterator: Removed as it too is not a list comprehension.
(→‎C# Iterator: Removed as it too is not a list comprehension.)
Line 187:
}
</lang>
 
===Iterator===
<lang csharp>using System;
using System.Collections.Generic;
 
static class Program
{
static IEnumerable<Tuple<int, int, int>> GetPythTriples(int upperBound)
{
for (int a = 1; a <= upperBound; a++)
for (int b = a + 1; b <= upperBound; b++)
for (int c = b + 1; c <= upperBound; c++)
if (a * a + b * b == c * c)
yield return new Tuple<int, int, int>(a, b, c);
}
 
static void Main()
{
foreach (var triple in GetPythTriples(20))
Console.WriteLine(triple);
}
}</lang>
 
=={{header|C++}}==
Anonymous user