mardi 26 septembre 2017

Converting if-else to for loop

            if (range <= 10){
                a[0]= value;
            }

            else if (range > 10 && range <= 20){
                a[1]= value;
            }

            else if (range> 20 && range <= 30){
                a[2]= value;
            }

            else if (range > 30 && range <= 40){
                a[3]= value;
            }

            else if (range> 40 && <= max_range){
                a[4]= value;
            }

It is simple code. I would like it to remove the nested else if's and use a for loop. How can I convert this into a for loop?

Aucun commentaire:

Enregistrer un commentaire