00 Votes

Foreach Loop in Lazarus?

Question by Guest | 2014-02-08 at 12:20

Recently, I have often coded using the programming language PHP, at the moment I am working with Lazarus again.

What I am missing from the PHP-world is the foreach-loop with which it is very easy to go through and array element for element.

Lazarus does not seem to know the key word "foreach". Anyway, is there any possibility to run through an array in an easy way? Foreach is so convenient and fast!

ReplyPositiveNegative
3Best Answer3 Votes

When I was working with Delphi some years ago, I have also missed the foreach loop. But Lazarus has it, but it is not called FORACH but FOR IN:

var
  s: string;
begin
  for s in arr do showmessage(s);

In this example, "arr" is a string-array and we are traversing it using the for-in-loop. In each way through, we have the current content from the array in our variable "s".

Using this, working with Lazarus makes even more fun!
2014-02-09 at 12:43

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.