kiki78 Active Member Licensed User Longtime User Jan 16, 2015 #1 If I put While or Until at end of Do..Loop I receive Syntax Error. Code: Copy Dim i As Int = 0 Do i = i + 1 Loop While i < 10
If I put While or Until at end of Do..Loop I receive Syntax Error. Code: Copy Dim i As Int = 0 Do i = i + 1 Loop While i < 10
eps Expert Licensed User Longtime User Jan 16, 2015 #2 Isn't it... Code: Copy Do While i < 10 'processing i=i+1 Loop ? from here : http://www.b4x.com/android/help/core.html
Isn't it... Code: Copy Do While i < 10 'processing i=i+1 Loop ? from here : http://www.b4x.com/android/help/core.html
kiki78 Active Member Licensed User Longtime User Jan 16, 2015 #3 Sorry eps, but it's not the same. Both syntax are normally correct, but with test at end, first loop is always execute. This is rarely used but sometime interesting.
Sorry eps, but it's not the same. Both syntax are normally correct, but with test at end, first loop is always execute. This is rarely used but sometime interesting.
Erel B4X founder Staff member Licensed User Longtime User Jan 18, 2015 #4 Do... Loop While syntax is currently not supported.
kiki78 Active Member Licensed User Longtime User Jan 18, 2015 #5 Ok Erel, I put it in bug as I never see that /https://www.b4x.com/android/forum/threads/comment-after-do-keyword.587/ is for ppc and not android. So move it as Wish instead Bug Regards, Last edited: Jan 18, 2015
Ok Erel, I put it in bug as I never see that /https://www.b4x.com/android/forum/threads/comment-after-do-keyword.587/ is for ppc and not android. So move it as Wish instead Bug Regards,
DonManfred Expert Licensed User Longtime User Jan 19, 2015 #6 kiki78 said: So move it as Wish instead Bug Click to expand... You can change the threads title to wish Use threadtools above your 1st post
kiki78 said: So move it as Wish instead Bug Click to expand... You can change the threads title to wish Use threadtools above your 1st post
T Troberg Well-Known Member Licensed User Longtime User Jan 23, 2015 #8 I agree, this is sometimes useful, and would be nice to have. For example, a typical "try until you succeed"-scenario: Code: Copy Do InitMeasurementProbe() StartMeasure() Do Until MeasuredValueReady() DoEvents Loop Measurement=GetMeasurement() CloseMeasurementProbe() Loop Until Measurement<>BadValue LogFile(Measurement) In VB, there were also several places where the framework was based upon a "do until you fail"-scenario. Read files listings with Dir, which returned "" when there was no more files left to list, or when looping in database recordsets. I don't know how common this is in B4A, but I suspect they can happen.
I agree, this is sometimes useful, and would be nice to have. For example, a typical "try until you succeed"-scenario: Code: Copy Do InitMeasurementProbe() StartMeasure() Do Until MeasuredValueReady() DoEvents Loop Measurement=GetMeasurement() CloseMeasurementProbe() Loop Until Measurement<>BadValue LogFile(Measurement) In VB, there were also several places where the framework was based upon a "do until you fail"-scenario. Read files listings with Dir, which returned "" when there was no more files left to list, or when looping in database recordsets. I don't know how common this is in B4A, but I suspect they can happen.
Erel B4X founder Staff member Licensed User Longtime User Jan 25, 2015 #9 Note that the code you posted cannot work. You should not try to hold the main thread with such loops. The event will never fire.
Note that the code you posted cannot work. You should not try to hold the main thread with such loops. The event will never fire.
T Troberg Well-Known Member Licensed User Longtime User Jan 25, 2015 #10 It's just pseudocode to make a point. Just remove the doevents and it would work (depending on what made the measurement value ready). My point is that there are several legitimate cases of "Do this at least once until we get a desired result".
It's just pseudocode to make a point. Just remove the doevents and it would work (depending on what made the measurement value ready). My point is that there are several legitimate cases of "Do this at least once until we get a desired result".
cimperia Active Member Licensed User Longtime User Apr 29, 2015 #11 A bit late on this one, but I was looking for the same loop construct as kiki78. No joy. Fortunately it's possible to keep the same logic with what we have at hand. For example re-using Troberg example Code: Copy Do While True InitMeasurementProbe() StartMeasure() Do Until MeasuredValueReady() DoEvents Loop Measurement=GetMeasurement() CloseMeasurementProbe() If Measurement<>BadValue Then Exit 'Loop Loop LogFile(Measurement) or Code: Copy dim On As Boolean = True Do While On InitMeasurementProbe() StartMeasure() Do Until MeasuredValueReady() DoEvents Loop Measurement=GetMeasurement() CloseMeasurementProbe() If Measurement<>BadValue Then On = False Loop LogFile(Measurement)
A bit late on this one, but I was looking for the same loop construct as kiki78. No joy. Fortunately it's possible to keep the same logic with what we have at hand. For example re-using Troberg example Code: Copy Do While True InitMeasurementProbe() StartMeasure() Do Until MeasuredValueReady() DoEvents Loop Measurement=GetMeasurement() CloseMeasurementProbe() If Measurement<>BadValue Then Exit 'Loop Loop LogFile(Measurement) or Code: Copy dim On As Boolean = True Do While On InitMeasurementProbe() StartMeasure() Do Until MeasuredValueReady() DoEvents Loop Measurement=GetMeasurement() CloseMeasurementProbe() If Measurement<>BadValue Then On = False Loop LogFile(Measurement)
T Troberg Well-Known Member Licensed User Longtime User May 4, 2015 #12 Well, you can, of course do it in other ways, but they tend to be somewhat oblique and harder to follow, increasing the risk of bugs.
Well, you can, of course do it in other ways, but they tend to be somewhat oblique and harder to follow, increasing the risk of bugs.
cimperia Active Member Licensed User Longtime User May 4, 2015 #13 You won't get an argument from me. I agree that the built-in construct is cleaner and less prone to buggy code, I was merely pointing out that it was possible to get a near identical logic in this specific case.
You won't get an argument from me. I agree that the built-in construct is cleaner and less prone to buggy code, I was merely pointing out that it was possible to get a near identical logic in this specific case.
E emexes Expert Licensed User Longtime User Jul 1, 2019 #14 +1 Microsoft may be the devil to some, but their orthogonal loop construct is a beautiful thing: Code: Copy DO [{WHILE | UNTIL} condition] [EXIT DO] [CONTINUE {DO | LOOP}] LOOP [{WHILE | UNTIL} condition] No, wait, maybe it's PowerBASIC. Or VAX BASIC. Regardless: is good. Last edited: Jan 17, 2023
+1 Microsoft may be the devil to some, but their orthogonal loop construct is a beautiful thing: Code: Copy DO [{WHILE | UNTIL} condition] [EXIT DO] [CONTINUE {DO | LOOP}] LOOP [{WHILE | UNTIL} condition] No, wait, maybe it's PowerBASIC. Or VAX BASIC. Regardless: is good.
LucaMs Expert Licensed User Longtime User Jul 1, 2019 #15 I agree, Do - Loop {White | Until} is often useful. But we can live even without it
E emexes Expert Licensed User Longtime User Jul 1, 2019 #16 LucaMs said: But we can live even without it Click to expand... Yes, but we can live even better with it - the more that code can be like natural language, the less translation effort is needed from code to thought and vice versa. And, in Australia at least, Italians are known for enjoying life.
LucaMs said: But we can live even without it Click to expand... Yes, but we can live even better with it - the more that code can be like natural language, the less translation effort is needed from code to thought and vice versa. And, in Australia at least, Italians are known for enjoying life.
LucaMs Expert Licensed User Longtime User Jul 1, 2019 #17 emexes said: Italians are known for enjoying life Click to expand... There are always exceptions
E emexes Expert Licensed User Longtime User Jul 2, 2019 #18 LucaMs said: There are always exceptions Click to expand... If you are talking about programming language structure - agreed. But we can resist. That is the beauty of making a language more orthagonal and regular - it reduces the number of exceptions, increases your options, reduces your mental workload, leaves you more thought-power to apply to solving the actual problem rather than fitting within language constraints. If you are talking about the Italian natural bent towards enjoying life - all I can say is that the Italians I've grown up with here are a very cheerful bunch, even before adding wine.
LucaMs said: There are always exceptions Click to expand... If you are talking about programming language structure - agreed. But we can resist. That is the beauty of making a language more orthagonal and regular - it reduces the number of exceptions, increases your options, reduces your mental workload, leaves you more thought-power to apply to solving the actual problem rather than fitting within language constraints. If you are talking about the Italian natural bent towards enjoying life - all I can say is that the Italians I've grown up with here are a very cheerful bunch, even before adding wine.
LucaMs Expert Licensed User Longtime User Jul 2, 2019 #19 The second one. You should watch an italian movie: https://en.wikipedia.org/wiki/A_Girl_in_Australia (its original title is very different, you can read it there). I think that in this case, "do - loop while", this fact does not complicate the programmer's life much or even the readability of the code, but it is useful to avoid duplicating one or two lines of code. Rather, I feel the need for something else, for which perhaps a few threads have already been created in the "Bug & Wishlist" forum but I still want to open a new one, because just yesterday I happened to need it and I consider it much more important, its "absence" involves many problems.
The second one. You should watch an italian movie: https://en.wikipedia.org/wiki/A_Girl_in_Australia (its original title is very different, you can read it there). I think that in this case, "do - loop while", this fact does not complicate the programmer's life much or even the readability of the code, but it is useful to avoid duplicating one or two lines of code. Rather, I feel the need for something else, for which perhaps a few threads have already been created in the "Bug & Wishlist" forum but I still want to open a new one, because just yesterday I happened to need it and I consider it much more important, its "absence" involves many problems.
E emexes Expert Licensed User Longtime User Jul 2, 2019 #20 LucaMs said: The second one. You should watch an italian movie: https://en.wikipedia.org/wiki/A_Girl_in_Australia Click to expand... That looks like an interesting movie. Probably a bit heartbreaking in places - seems to be mostly decent people each trying to improve their situation, during a period when life was difficult anyway. But still holds now: Life is what you make of it. the readability of the code Click to expand... It is easier to create art when the medium is pliable avoid duplicating one or two lines of code Click to expand... It's not the volume of code I care about (otherwise I'd voting to for the brevity of C, or even APL) but how well that code aligns with its intent, and thus how easy it is to understand what the code means to do. Eg, if I see FOR I = 1 TO 10 : stuff : NEXT I then I know understand stuff is meant to happen 10 times. If I see I = 1 : DO WHILE I < 10 : stuff : I = I + 1 : LOOP then I have to think a bit harder to arrive at the same understanding. Rather, I feel the need for something else ... I consider it much more important, its "absence" involves many problems. Click to expand... What is that something else? Given that we both seem passionate about B4A being a better language, I'll probably hop on that bandwagon with you too Last edited: Sep 8, 2020
LucaMs said: The second one. You should watch an italian movie: https://en.wikipedia.org/wiki/A_Girl_in_Australia Click to expand... That looks like an interesting movie. Probably a bit heartbreaking in places - seems to be mostly decent people each trying to improve their situation, during a period when life was difficult anyway. But still holds now: Life is what you make of it. the readability of the code Click to expand... It is easier to create art when the medium is pliable avoid duplicating one or two lines of code Click to expand... It's not the volume of code I care about (otherwise I'd voting to for the brevity of C, or even APL) but how well that code aligns with its intent, and thus how easy it is to understand what the code means to do. Eg, if I see FOR I = 1 TO 10 : stuff : NEXT I then I know understand stuff is meant to happen 10 times. If I see I = 1 : DO WHILE I < 10 : stuff : I = I + 1 : LOOP then I have to think a bit harder to arrive at the same understanding. Rather, I feel the need for something else ... I consider it much more important, its "absence" involves many problems. Click to expand... What is that something else? Given that we both seem passionate about B4A being a better language, I'll probably hop on that bandwagon with you too