Thanks!
Do or Repeat While() on wish list...
Do or Repeat While() on wish list...
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... 
Thanks!
Thanks!
Re: Do or Repeat While() on wish list...
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
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Do or Repeat While() on wish list...
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

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Do or Repeat While() on wish list...
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: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.
Code: Select all
Macro WhileEx(condition)
Until Not (condition)
EndMacro
Define i.i
i = 0
Repeat
i + 1
WhileEx(i < 10)
Debug ibye,
Daniel
Daniel
Re: Do or Repeat While() on wish list...
Can't you do something like...
I guess I'm not properly understanding the question 
Code: Select all
While Not ( ... load of crap ... )
...
Wend
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
DarkDragon
- Addict

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Do or Repeat While() on wish list...
This is a head controlled loop. Learn the basics of programming please!!blueznl wrote:Can't you do something like...
I guess I'm not properly understanding the questionCode: Select all
While Not ( ... load of crap ... ) ... Wend
bye,
Daniel
Daniel
Re: Do or Repeat While() on wish list...
So...
?
Code: Select all
Repeat
...
Until Not ( ... load of crap ...)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Do or Repeat While() on wish list...
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!)
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.
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!)
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

- Posts: 2348
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Do or Repeat While() on wish list...
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.blueznl wrote:So...
?Code: Select all
Repeat ... Until Not ( ... load of crap ...)
bye,
Daniel
Daniel
Re: Do or Repeat While() on wish list...
Why should Fred waste his time implementing a whole new loop just because you won't use the Not operator?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!
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
Re: Do or Repeat While() on wish list...
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
)
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 - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Do or Repeat While() on wish list...
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.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)
Re: Do or Repeat While() on wish list...
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.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)
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
