ID:1599008
 
(See the best response by LordAndrew.)
Code:
do
sleep(70)
m.sold+=sold*7
m.soldweek=sold*7
src.money*=m.soldweek*10
sold*=0.75
while(m.soldweek>100)


I never could figure when I would need the loop to do once before it checks again so here it happened. Its because you start out with 0 sold out of this business of the tycoon game the week it first sold out until the first week is over so it needs to do once and if it sells 100 or less it will stop but not for if its sold a lot.
It might be because of the lack of punctuation, but I'm not really seeing a question here. Did you intend to post this in Developer Help?
The question is has anyone ever used do_while loop before? In what other situations should I use do_while loop?
In response to TheDarkChakra
It's essentially for making sure that the code within the do block is executed at least once before the loop begins.
In response to LordAndrew
Example?
In response to TheDarkChakra
Best response
// Keep the name under a certain length.
var const/NAME_LENGTH = 20
// Look for profanity in the user name.
proc/has_profanity(str)
// Assume I filled this in.

mob/Login()
..()
do
src.name = input("Please enter your desired name.", "Set Name", src.name)
while (has_profanity(src.name) || length(src.name) > NAME_LENGTH || length(src.name) == 0)
In LA example, if you don't have the "do" proc then it would still work the same way cause alert messages freeze you?
In response to Flysbad
Flysbad wrote:
In LA example, if you don't have the "do" proc then it would still work the same way cause alert messages freeze you?

I assume you are asking that if the "do" was removed, will it cause you to freeze?

If so, yes, with the way it is currently written.

As mentioned earlier, doing do..while causes the code block to runs first then execute the while() [which then repeats until the conditions are satisfied].

If you remove the do here, you are asking the user to input a user name and, if invalid and without any other escapes, you are stuck in an infinite loop because there is nothing that will change the name (thus the condition is always satisfied).

With the do, it will repeat back to the input() so now you have the chance to change the conditions (thus no infinite loop* [unless there was a bug/typo in one of the subprocs]).

If you did not want the do for the example, the same effect could be achieved by placing the input beneath the while() statement block.


But the whole point of that snippet was to demonstrate that the code block within the 'do' section is called first THEN the while() conditions are checked.