mardi 15 janvier 2019

Why should I type i++; outside the if block?

When finding max value from array why should i type i++ outside the if block?

int[] x = new int[] { 5, 7, -100, 400, 8 };

int i = 1;
int max;

max = x[0];

while (i < x.Length)
{
    if (x[i] > max)
    {
        max = x[i];
    }
    i++;
}
Console.WriteLine("MAX="+max);

Aucun commentaire:

Enregistrer un commentaire