Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 252
Mohammed Housseyn Taleb Avatar asked Jan 29 '15 15:01

Mohammed Housseyn Taleb


People also ask

Is Object Pascal and Delphi the same?

Originally Answered: What are the differences between Delphi and Pascal ? That's pretty simple: Pascal is the language, and Delphi is a product line that implements that language. Technically Delphi is a version of Object Pascal, just like Freepascal.


1 Answers

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.
like image 101
RRUZ Avatar answered Oct 16 '22 23:10

RRUZ