foreach syntax problem?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
abma
Posts: 3
Joined: 19 Feb 2020 10:16

foreach syntax problem?

Post by abma »

I want to do 100 loops, the foreach command can only be entered manually? :cry:

Code: Select all

foreach ($token, 1,2,3,4..., ",") {
	msg $token;
}
Writing in other languagesin

Code: Select all

for i in range(100)......
for i = 1 to 100 ......

RalphM
Posts: 2055
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: foreach syntax problem?

Post by RalphM »

Welcome to the forum.

Why don't you use a while loop with an internal counter.
Ralph :)
(OS: W11 24H2 Home x64 - XY: Current x32 beta - Office 2024 32-bit - Display: 1920x1080 @ 125%)

abma
Posts: 3
Joined: 19 Feb 2020 10:16

Re: foreach syntax problem?

Post by abma »

I'm good at looping with "for ...", it can control the looping rules very well. "While ..." I rarely use it. I only use "if ..." and "for ..." when programming

RalphM
Posts: 2055
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: foreach syntax problem?

Post by RalphM »

XY's scripting language is loosely based on PHP's but AFAIK there is no "for" command available in XY, so you will have to make do with "while".
Ralph :)
(OS: W11 24H2 Home x64 - XY: Current x32 beta - Office 2024 32-bit - Display: 1920x1080 @ 125%)

jupe
Posts: 3324
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: foreach syntax problem?

Post by jupe »

I would also recommend using a while loop for what you are trying to do, foreach doesn't really suit what you are wanting to do, in saying that though, if you really won't adapt and use a while loop, then here is one way of implementing what you want using foreach:

Code: Select all

  foreach($i, strrepeat('1', 100), '') { ........... }

Post Reply