J'ai un tableau avec des objets PointType:
const coords : array[0..6] of PointType =
((x:220, y:410),
(x:120, y:110),
(x:480, y: 60),
(x:320, y:200),
(x:560, y:190),
(x:390, y:360),
(x:600, y:440));
que je dois faire une boucle pour parcourir tous ces points, mais en utilisant trois d'entre eux dans chaque itteration et revenir au début. Comme ceci:
arrayLength := SizeOf(coords) div SizeOf(PointType);
for i := 1 to (arrayLength-2)
do begin
WriteLn(someFunction(coords[i-1], coords[i], coords[i+1]));
end;
WriteLn(someFunction(coords[arrayLength - 2], coords[arrayLength - 1], coords[0]));
WriteLn(someFunction(coords[arrayLength - 1], coords[0], coords[1]));
Y a-t-il une bonne façon de faire cela en une seule action, sans spécifier les deux dernières itérations?
Merci!
Je ne vois une itération (pour) dans votre exemple de code? Ou voulez-vous dire au cas où le nombre d'éléments à inspecter est variable? –