Do or Repeat While() on wish list...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Do or Repeat While() on wish list...

Post by Tenaja »

I'd like to request a Repeat {command list} while (condition) statement. I know it's very similar to Repeat Until, but sometimes it's easier or more readable to repeat WHILE a condition is true rather than UNTIL it's not true. Especially if the condition has quite a few tests that span several lines... 8)

Thanks!
User avatar
Blood
Enthusiast
Enthusiast
Posts: 161
Joined: Tue Dec 08, 2009 8:34 pm
Location: United Kingdom

Re: Do or Repeat While() on wish list...

Post by Blood »

This request makes no sense whatsoever. You already have all the types of loop you need.
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Do or Repeat While() on wish list...

Post by netmaestro »

The While..Wend block does exactly what you ask, it just doesn't use the Repeat keyword before While. It's already implemented.
BERESHEIT
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Do or Repeat While() on wish list...

Post by DarkDragon »

netmaestro wrote:The While..Wend block does exactly what you ask, it just doesn't use the Repeat keyword before While. It's already implemented.
No, thats a head controlled loop and no foot controlled like "Repeat : Until". He just wants to have a "do : while" loop like "Repeat : Until" but without inverting the Until block. But he could also just use Macros and build it himself:

Code: Select all

Macro WhileEx(condition)
  Until Not (condition)
EndMacro

Define i.i
i = 0
Repeat
  i + 1
WhileEx(i < 10)
Debug i
bye,
Daniel
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Do or Repeat While() on wish list...

Post by blueznl »

Can't you do something like...

Code: Select all

While Not ( ... load of crap ... )
  ...
Wend
I guess I'm not properly understanding the question :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Do or Repeat While() on wish list...

Post by DarkDragon »

blueznl wrote:Can't you do something like...

Code: Select all

While Not ( ... load of crap ... )
  ...
Wend
I guess I'm not properly understanding the question :-)
This is a head controlled loop. Learn the basics of programming please!! :lol: See my code for what he wants. The foot controlled loop will ALWAYS pass at least once.
bye,
Daniel
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Do or Repeat While() on wish list...

Post by blueznl »

So...

Code: Select all

Repeat
  ...
Until Not ( ... load of crap ...)
?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Do or Repeat While() on wish list...

Post by Tenaja »

Thankfully, the ignorant have already been addressed. (Thanks.) For the opinionated... yes, we already have all the loops we "need," but if Fred quit at all we "need," then there would only be If/Goto statements!

On the other hand, this forum is called the "Feature Requests and Wishlists" forum. I, personally, prefer to look for conditions without inverting them. Hence, the "wish."

Here is a comparison of eating newlines on a text file...

Repeat
getnextchar
until (!newline or EOF)

vs.
Repeat
getnextchar
while (newline and !EOF)

Clearly, they do the same thing, and the logic gives the same result. However, depending upon the intent of the code, repeating while you are eating newlines may be "easier" to read than eating until you have no newlines.

It's back to the "glass half full or half empty" argument. (For me, it depends on which direction I'm going!) :D
No, I don't expect Fred et al to jump every time I ask for something, but at least I ask for things that are simple to implement, and he's free to ignore my request anyway.
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Do or Repeat While() on wish list...

Post by DarkDragon »

blueznl wrote:So...

Code: Select all

Repeat
  ...
Until Not ( ... load of crap ...)
?
Yes, exactly thats what he wants. But its not useful and more complicating the syntax. Other languages also only have one statement for foot controlled loops.
bye,
Daniel
User avatar
Blood
Enthusiast
Enthusiast
Posts: 161
Joined: Tue Dec 08, 2009 8:34 pm
Location: United Kingdom

Re: Do or Repeat While() on wish list...

Post by Blood »

Tenaja wrote:Thankfully, the ignorant have already been addressed. (Thanks.) For the opinionated... yes, we already have all the loops we "need," but if Fred quit at all we "need," then there would only be If/Goto statements!
Why should Fred waste his time implementing a whole new loop just because you won't use the Not operator?
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Do or Repeat While() on wish list...

Post by blueznl »

Well, it's a WISH list, so we can all post things we'd like to see in our favorite language. The good thing about a forum is that we (users) can spar a bit about the usability of the feature, and they (the devs) can see what's interesting to the community, and how the community would react to certain ideas.

I thought I was overlooking something, but now I understand :-)

By the way, I strongly believe loops with the conditional parameter WHEN ENTERING are often a better way to program, as they keep code more readable. Again, it's a matter of choice, but isn't that the case with anything? (Including girlfriends :-))
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Do or Repeat While() on wish list...

Post by Tenaja »

blueznl wrote: By the way, I strongly believe loops with the conditional parameter WHEN ENTERING are often a better way to program, as they keep code more readable. Again, it's a matter of choice, but isn't that the case with anything? (Including girlfriends :-))
While I agree, in principle, there are two problems... either the loop isn't guaranteed to run a minimum of once (as in repeat...until or do...while) OR the compilers parsing of it is a huge pain because you'd have to buffer the conditional test and paste it at the end of the loop code. And since most compilers don't buffer code, that would be a huge rework of the system.
User avatar
Blood
Enthusiast
Enthusiast
Posts: 161
Joined: Tue Dec 08, 2009 8:34 pm
Location: United Kingdom

Re: Do or Repeat While() on wish list...

Post by Blood »

blueznl wrote:By the way, I strongly believe loops with the conditional parameter WHEN ENTERING are often a better way to program, as they keep code more readable. Again, it's a matter of choice, but isn't that the case with anything? (Including girlfriends :-))
Matter of choice is not an option, both forms are needed to solve certain problems. For example a bubble sort algorithm can be more elegantly solved using a do...while loop.

The loops as they are, are fine.
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
Post Reply