samedi 22 octobre 2016

How do you convert an if else statement into a for loop?

I am creating an if else statement that will determine if a year is a leap year or not. I already coded an if else statement that works but I am not sure which variable will go where into a for loop to make it repeat.

if (year%4==0 || year%100==0 && !not)
     System.out.println (year + " is a leap year");

    else
        System.out.println (year + " is not a leap year");

How would the for loop look like if I convert it into a for loop? Would the if else statement be inside of the for loop or just taken away from the code?

Aucun commentaire:

Enregistrer un commentaire