November 2019
Beginner to intermediate
674 pages
15h
English
Since version 2005, Delphi supports a concept of iteration over containers. In this version, a classical for..to statement was extended with a for..in counterpart. It allows us to iterate over arrays, strings, sets, and any other data structure without referring to the implementation details. For example, the for i := 0 to list.Count - 1 do statement from the beginning of this chapter can be rewritten as follows:
for el in list do Process(el);
This code will execute the body of the for loop once for each element in the list. In each iteration, the el variable will be set to that element. This for..in loop is functionally equivalent to the following code:
for i := 0 to list.Count - 1 dobegin el := list[i]; ...
Read now
Unlock full access