Android Question Do while/until with test at the end of the loop?

wimpie3

Well-Known Member
Licensed User
Longtime User
Maybe I'm overlooking something... We currently have

B4X:
Do while condition=true
(my code)
loop

or

B4X:
Do until condition=true
(my code)
loop

But they all test the condition BEFORE beginning the loop. Is there a way to do this right before reaching the end of the loop? Like

B4X:
Do
(my code)
Until condition=true
 

DonManfred

Expert
Licensed User
Longtime User
But they all test the condition BEFORE beginning the loop. Is there a way to do this right before reaching the end of the loop? Like
Do until condition=true (my code) loop:
Do until condition=true
(my code)
loop
will WORK if you set condition to true before the loop-line!!!
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Yes, in this particular case. But your suggestion does not work when I'm moving the pointer in a recordset with .nextrow.

I want something like this:
Do
(my code)
Until not(recordset.nextrow)

This moves the recordpointer AFTER my code has been executed.

When I do this:
Do until not(recordset.nextrow)
(my code)
Loop

the record pointer is already moved forward BEFORE it reaches my code.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
What does (my code) do? doesn't it handle recordsets?
 
Last edited:
Upvote 0

Didier99

Member
Licensed User
- B4X is not VB and also not related to VB.
But a large appeal of B4X (and used a lot in advertisements) is that the syntax is familiar to VB users. From the B4X home page:

My very first project in B4X was the conversion of a large VB project that went so quickly and so well I could not believe it, precisely because I was able to reuse a lot of existing code. That original code was written under vb6.0 (1998) and it's still there, 30 years later, some functions are untouched.
So when we (former VB users, now B4X users) come across something that sounds like it should be there, we have to say something

Edit: My code started with QuickBasic 4.5, which predates VB 6.0. QB4.5 was released in 1985, 40 years ago
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
The third way
B4X:
Dim b As Boolean
Do Until b
    YourCode
    b = Not(rs.NextRow)
Loop
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Do until condition=true (my code) loop:
Do until condition=true
(my code)
loop
will WORK if you set condition to true before the loop-line!!!
i think you meant "Do while" will work if you set condition to true before the loop-line!!! (and condition should change to false in the loop to exit it)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…