In the example below, how would I stop printing the positions of this vector that are equal to 0
int[] caluculo = {50,6,0,59,6,7,0,6,8};
for(int i = 0 ; i < 9 ; i++)
{
Console.WriteLine("{0}",calculo[i]);
}
In the example below, how would I stop printing the positions of this vector that are equal to 0
int[] caluculo = {50,6,0,59,6,7,0,6,8};
for(int i = 0 ; i < 9 ; i++)
{
Console.WriteLine("{0}",calculo[i]);
}
Whenever you need to filter something you should if
:
for (var i = 0 ; i < 9 ; i++) if (calculo[i] != 0) WriteLine(calculo[i]);
Or you can do
foreach (var item in calculo) if (item != 0) WriteLine(item);
You can also use LINQ, but I do not think it compares and is more advanced.