Page 1 of 1

Curious why no do while flow control

Posted: Fri Jun 01, 2018 7:33 pm
by Meeply
I noticed the addition of the /while loop flow control (I believe I was told @eqmule is to thank), kind of wondered why there is no corresponding do while loop for flow control.

Is it a problem with parsing because all statements need a / in front to notate a command and

Code: Select all

/do {
} while( condition)
does not have an appropriate place for a slash? Just looking for a little history or limitations to help my understanding. It is not a request unless its a couple lines change. I'd imagine its easily worked around with a variable define.

Code: Select all

/declare done_once int local 0
/while( condition || !${done_once} ) {
     |do something

     /varset done_once 1
}
/deletevar done_once
I imagine would work reasonably well? Still leaning syntax. Did I get that right?
Other options could be a /dowhile command but it appears awkward and non-obvious.

Just put it in the curious pile.

Thanks.

Re: Curious why no do while flow control

Posted: Sat Jun 02, 2018 8:29 pm
by exspes007

Re: Curious why no do while flow control

Posted: Sun Jun 03, 2018 2:31 am
by Meeply
Thanks, was asking about do while loop where the condition is checked at the end of the loop instead of the beginning.

Re: Curious why no do while flow control

Posted: Mon Jul 16, 2018 7:15 pm
by jrwalz
I tried to use that /do while some time ago because there was an actual example of it being available, but I gave up. You can do anything with the /while loop, just have to think backwards. Thinking of the /while loop like an /if condition statement helps to visualize it, but I'm sure that you know all of that and just wanted to actually know if it is available. Short answer, not to my knowledge.

Re: Curious why no do while flow control

Posted: Wed Jul 18, 2018 12:34 pm
by el_nene
Meeply wrote:
Fri Jun 01, 2018 7:33 pm
I noticed the addition of the /while loop flow control (I believe I was told @eqmule is to thank), kind of wondered why there is no corresponding do while loop for flow control.

Is it a problem with parsing because all statements need a / in front to notate a command and
Back in time, when I did the plugin that added the loops I did a:

Code: Select all

/do
/until (condition)
to allow this kinds of bucles. I think eqmule integrated that plugin in the MQ2 core, or at least parts of it.

I left EQ years ago (I still have the old habit to come here from time to time to read the forum), but when I was playing with the parse it had some limitations and the flow control required to be careful when adding this kind of commands. At the end, it was a lot of more easier to add flow control modifiers in independent commands (like the /until) that check if closing brackets could have a condition after it.