Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : while PLUS until
Author | Message | ||||
kiiid Guru Joined: 11/05/2013 Location: United KingdomPosts: 671 |
Only today I discovered that it is impossible to make a structure DO WHILE .... LOOP UNTIL Would it be too hard to have it? Increases flexibility significantly if the two conditions are different. http://rittle.org -------------- |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1421 |
You can't test the "UNTIL" condition at the end of the loop and exit (EXIT DO) the loop? Micromites and Maximites! - Beginning Maximite |
||||
kiiid Guru Joined: 11/05/2013 Location: United KingdomPosts: 671 |
Of course I can (and do), but it is not as elegant :) http://rittle.org -------------- |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5923 |
What about EXIT DO Jim VK7JH MMedit MMBasic Help |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3167 |
While it can be done it would not be BASIC as we know it and it would be messy to explain. Also, I am not sure that it would be "elegant", rather the opposite because most people reading the program would be thoroughly confused. Geoff Geoff Graham - http://geoffg.net |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1085 |
How about: DO
<statements> IF condition THEN EXIT LOOP Visit Vegipete's *Mite Library for cool programs. |
||||
Chris Roper Senior Member Joined: 19/05/2015 Location: South AfricaPosts: 280 |
Is that not the same as: DO
<statements> UNTIL condition http://caroper.blogspot.com/ |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3678 |
If you mean DO WHILE exp1 .... LOOP UNTIL exp2 then it's trivial to do as people have posted. C has the same way of solving it and it works really well. In effect you do DO WHILE exp1 .... IF exp2 THEN EXIT LOOP (bit hazy on MMBasic syntax) John |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1085 |
Exactly the same in my books. But I realize upon reflection that neither is exactly what kiiid asked for in the original posting. I was taught that a 'DO <stuff> UNTIL <condition>' structure is appropriate when you need to do the <stuff> at least once. In contrast, the 'WHILE <condition> <stuff> DO' structure can result in the <stuff> never being done. (Like household chores sometimes.) So kiiid wants something that will do <stuff> at least once based on one condition but possibly not at all based on a different condition. The logic starts to get a bit hairy... Visit Vegipete's *Mite Library for cool programs. |
||||
Chris Roper Senior Member Joined: 19/05/2015 Location: South AfricaPosts: 280 |
How about: [code] IF condition1 MySub Do While condition2 MySub Loop [/code] http://caroper.blogspot.com/ |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3678 |
I believe the right answer for what was asked has been posted, though it's quite possible that some other thing was meant. There are several common idioms in C (and wow are there a lot of examples on the net) for this kind of thing and they translate easily into MMBasic without needing weird or repeated code. John |
||||
Print this page |