Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 23:09 18 May 2024 Privacy Policy
Jump to

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 Kingdom
Posts: 671
Posted: 05:32am 23 May 2016
Copy link to clipboard 
Print this post

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 States
Posts: 1421
Posted: 06:59am 23 May 2016
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 671
Posted: 08:24am 23 May 2016
Copy link to clipboard 
Print this post

Of course I can (and do), but it is not as elegant :)

http://rittle.org

--------------
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 12:02pm 23 May 2016
Copy link to clipboard 
Print this post

What about
EXIT DO

Jim
VK7JH
MMedit   MMBasic Help
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 02:03pm 23 May 2016
Copy link to clipboard 
Print this post

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: Canada
Posts: 1085
Posted: 07:56am 24 May 2016
Copy link to clipboard 
Print this post

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 Africa
Posts: 280
Posted: 08:21am 24 May 2016
Copy link to clipboard 
Print this post

  vegipete said   How about:
DO
<statements>
IF condition THEN EXIT
LOOP


Is that not the same as:

DO
<statements>
UNTIL condition



http://caroper.blogspot.com/
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3678
Posted: 10:18am 24 May 2016
Copy link to clipboard 
Print this post

  kiiid said   Only today I discovered that it is impossible to make a structure DO WHILE .... LOOP UNTIL

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: Canada
Posts: 1085
Posted: 09:47am 25 May 2016
Copy link to clipboard 
Print this post

  Chris Roper said  
  vegipete said   How about:
DO
<statements>
IF condition THEN EXIT
LOOP


Is that not the same as:

DO
<statements>
UNTIL condition


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 Africa
Posts: 280
Posted: 10:21am 25 May 2016
Copy link to clipboard 
Print this post

  vegipete said  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...


How about:
[code]
IF condition1 MySub
Do While condition2
MySub
Loop
[/code]


http://caroper.blogspot.com/
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3678
Posted: 12:33pm 25 May 2016
Copy link to clipboard 
Print this post

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.

JohnEdited by JohnS 2016-05-26
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024