helloworld:algorithms:loop
Ceci est une ancienne révision du document !
n boucles imbriquées
Ici, dataLoop
contient pour chaque boucle la lettre, l'itération en cours (base 0) et le nombre d'itérations à réaliser.
public class DataLoop { public char Lettre { get; set; } public int N { get; set; } public int NEnCours { get; set; } public DataLoop(char lettre, int n, int nEnCours) { this.Lettre = lettre; this.N = n; this.NEnCours = nEnCours; } } private void nestedLoopOperation(IList<DataLoop> dataLoop, int level) { if (level == length.Count) { // Opération à exécuter i*j*k*l*... fois } else { for (length[level].NEnCours = 0; length[level].NEnCours < length[level].N; length[level].NEnCours++) nestedLoopOperation(length, level + 1); } } nestedLoopOperation(dataLoop, 0);
helloworld/algorithms/loop.1478693529.txt.gz · Dernière modification : 2016/11/09 13:12 de root