Android Question Loop routine "problem"

kepler

Active Member
Licensed User
Longtime User
Hello again,

In my current script, I've tryed to do a Loop routine, similar to VB, but with the B4A rules.

The routine in VB is something like this:

B4X:
Do
(...procedures1...)
    If nt > sd Then
    Exit Loop ' ---------- EXIT
    End If
(...procedures2...)
Loop

I've tryed:

B4X:
Do Until (nt > sd)
   (...procedures1...)
   (...procedures2...)
Loop


But, from the several results I get, the last one is always wrong - so I suspect that this Loop in B4A is not working properly mainly because it's running procedures2 in sequence of procedures1.

Any tips or workarounds on this issue?

Kind regards,

Kepler
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Last time: please use code tags when posting code!!!!!!!
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
If you need to run procedures1 at least once before checking if nt > sd you could call it before entering the Do Until Loop. It's rather difficult to provide better help without knowing what your code does?

PS. You can exit the loop at any time using the command "Exit".
 
Upvote 0

kepler

Active Member
Licensed User
Longtime User
Can you take it easy?!!!! I've just read your input code instructions in the other post. If I knew how to do it, I wouldn't do it wrong again.
It's not my fault if you're upset today... Take it on someone else, please.

Kepler
 
Upvote 0

kepler

Active Member
Licensed User
Longtime User
Sorry RandomCoder. Here's the code:

B4X:
While True
            ad = ad + syn
            k2 = k1 + 1
            nt2 = Modulate(ad, k2)
            If nt1 <= sd And nt2 > sd Then
                Exit While ' ---------- EXIT
            End If
            nt1 = nt2
            k1 = k2
        End While

Kind regards,

Kepler
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Hi @kepler is the code you posted working as you expect now or is there still a problem. I'm unsure? :confused:
 
Upvote 0

kepler

Active Member
Licensed User
Longtime User
Hi. The code I've posted is in VB, as you know - and it works fine.
My adaptation to the language of B4A, however, gone terribly wrong up until now... :(

It works this way:

B4X:
Dim temp as Boolean = True

Do While temp
            ad = ad + syn
            k2 = k1 + 1
            nt2 = Modulate(ad, k2)
            If (nt1 <= sd And nt2 > sd) Then Exit
            nt1 = nt2
            k1 = k2
Loop

:)

Kind regards,

Kepler
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
@kepler I'm glad you've got it sorted, I only quickly read your previous example and thought that it was already written in B4A, which was why I couldn't understand what wasn't working. As you've now shown with the working code, there's very little difference between VB and B4A (just enough difference to trip us up! ;)). I program in a variety of similar but different languages and specialise in none, so I'm forever having to look up the correct syntax.
 
Upvote 0
Top