questions de boucle: for * if ou while + while
Bonjour,
Je me demande quel est le plus efficace (en terme de rapidite et de clarte) entre:
(c'est ecrit style C ou Python mais ma question s'appliquent a tous les langages qui gerent les boucles et conditions)
Code:
1 2 3 4 5 6 7 8 9 10
|
if(limit < 1) {
print "Error, argument 2 has to be strict positive."
return; }
for(i=0; i < aList.length(); i++) {
if(limit){ myFunction(aList[i]);
limit--; }
else theotherWay(aList[i]); } |
ou
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
if(limit < 1) {
print "Error, argument 2 has to be strict positive."
return; }
len = aList.length();
i=0;
limit = limit<len ? limit : len;
while(limit) {
myFunction(aList[i]);
i++
limit--; }
while(i<len){
theotherWay(aList[i]);
i++ } |
Ya peut etre mieux, sinon lequel choisir ?