Page 1 of 1
foreach syntax problem?
Posted: 21 Feb 2020 05:20
by abma
I want to do 100 loops, the foreach command can only be entered manually?
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 ......
Re: foreach syntax problem?
Posted: 21 Feb 2020 09:24
by RalphM
Welcome to the forum.
Why don't you use a while loop with an internal counter.
Re: foreach syntax problem?
Posted: 21 Feb 2020 16:34
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
Re: foreach syntax problem?
Posted: 21 Feb 2020 17:07
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".
Re: foreach syntax problem?
Posted: 22 Feb 2020 05:38
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), '') { ........... }