Curious why no do while flow control

A forum for feature requests/discussions and user submitted patches that improve MQ2

Moderator: MacroQuest Developers

Meeply
orc pawn
orc pawn
Posts: 13
Joined: Mon May 21, 2018 7:06 am
Location: Land of Lincoln

Curious why no do while flow control

Post by Meeply » 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

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.
No matter where you go, there you are.

exspes007
a hill giant
a hill giant
Posts: 193
Joined: Mon Oct 22, 2012 1:16 am

Re: Curious why no do while flow control

Post by exspes007 » Sat Jun 02, 2018 8:29 pm

-exspes007

Meeply
orc pawn
orc pawn
Posts: 13
Joined: Mon May 21, 2018 7:06 am
Location: Land of Lincoln

Re: Curious why no do while flow control

Post by Meeply » Sun Jun 03, 2018 2:31 am

Thanks, was asking about do while loop where the condition is checked at the end of the loop instead of the beginning.
No matter where you go, there you are.

jrwalz
decaying skeleton
decaying skeleton
Posts: 4
Joined: Sat Nov 04, 2017 10:47 pm

Re: Curious why no do while flow control

Post by jrwalz » Mon Jul 16, 2018 7:15 pm

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.

el_nene
a snow griffon
a snow griffon
Posts: 354
Joined: Tue Nov 02, 2004 1:28 pm

Re: Curious why no do while flow control

Post by el_nene » Wed Jul 18, 2018 12:34 pm

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.