Embarcadero Delphi Looping over characters of a string


Example

2005

The following iterates over the characters of the string s. It works similarly for looping over the elements of an array or a set, so long as the type of the loop-control variable (c, in this example) matches the element type of the value being iterated.

program ForLoopOnString;

{$APPTYPE CONSOLE}

var
  s : string;
  c : Char;
begin
  s := 'Example';
  for c in s do
    WriteLn(c);
end.

Output:

E
x
a
m
p
l
e