Android Question Loop routine "problem"

Discussion in 'Android Questions' started by kepler, Mar 16, 2015.

  1. kepler

    kepler Active Member Licensed 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:

    Code:
    Do
    (...procedures1...)
        
    If nt > sd Then
        
    Exit Loop ' ---------- EXIT
        End If
    (...procedures2...)
    Loop
    I've tryed:

    Code:
    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: Mar 16, 2015
  2. DonManfred

    DonManfred Expert Licensed User

    Last time: please use code tags when posting code!!!!!!!
     
  3. RandomCoder

    RandomCoder Well-Known Member Licensed 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".
     
  4. kepler

    kepler Active Member Licensed 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
     
  5. kepler

    kepler Active Member Licensed User

    Sorry RandomCoder. Here's the code:

    Code:
    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
     
  6. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Hi @kepler is the code you posted working as you expect now or is there still a problem. I'm unsure? :confused:
     
  7. kepler

    kepler Active Member Licensed 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:

    Code:
    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
     
  8. RandomCoder

    RandomCoder Well-Known Member Licensed 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.
     
    kepler likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice