Στον προγραμματισμό, ένας FOR προορισμός (πιο συχνά ονομάζεται iterable ή iteration source) ορίζει τη συλλογή τιμών που μια μεταβλητή βρόχου θα αναλάβει διαδοχικά κατά κάθε επανάληψη ενός FOR loop.
for identifier in destination: # loop body commands
Όπου:
numbers = [1, 2, 3, 4] for number in numbers: print(number) # Output: 1, 2, 3, 4 (κάθε ένα σε νέα γραμμή)
for number in range(5): print(number) # Output: 0, 1, 2, 3, 4
word = "Hello" for letter in word: print(letter) # Output: H, e, l, l, o
with open("myfile.txt", "r") as file: for line in file: print(line.strip())
ages = {"Alice": 30, "Bob": 25} for name, age in ages.items(): print(f"{name} is {age} years old")
unique_numbers = {1, 2, 3, 2, 1} for num in unique_numbers: print(num) # Output: 1, 2, 3 (η σειρά δεν εγγυάται)
__iter__() ή __getitem__() μπορεί να είναι FOR προορισμόςfor x, y in points:for-else της Python εκτελεί το else block αν ο βρόχος ολοκληρωθεί χωρίς breakΕνώ η σύνταξη διαφέρει, η έννοια υπάρχει σε όλες τις γλώσσες:
for (const item of iterable)for (Type item : collection)for (auto& item : container)foreach (var item in collection)