Mohammed Housseyn Taleb
Mohammed Housseyn Taleb

Reputation: 1828

Is there a way in delphi (Pascal object) to make a for each like in java?

i started today learning delphi. i m wondering if there is a way to make a delphi code like mine on java using the for each with array of objects. there is my java code:

     class test {
        public static void main(String[] args){

              String[] names={"ali","samad","kamel","djamel","mustapha"};

              for(String name:names){
                      System.out.println("user:"+name);
                  }
          }
       }

thanks.

Upvotes: 7

Views: 1746

Answers (1)

RRUZ
RRUZ

Reputation: 136431

You can use a for..in loop, like so

const
  names : array [0..4] of string  = ('ali','samad','kamel','djamel','mustapha');
var
 s : string;
begin
  try
    for s in names do
     Writeln(s);

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  readln;
end.

Upvotes: 8

Related Questions