Android Question Nested cycle For Next ( Return / Exit )

MarcoRome

Expert
Licensed User
Longtime User
Hi all. I have this code:
B4X:
Sub Button1_Click
Dim i, ii As Int
    For i = 0 To 100
        DoEvents
        Label1.Text = "First Cycle " & i
        For ii = 0 To 100
            DoEvents
            Label2.Text = "Next Cycle " & ii
            If i = 1 And ii = 70 Then Return
        Next
Next
End Sub

"Exit" is used to exit (escape) the for-loop, while-loop, switch-statement that you are currently executing and "Return" will exit the entire method you are currently executing (and possibly return a value to the caller, optional). Right ?

In my service i have this code:
B4X:
Sub SI_MessageReceived (From As String, Body As String) As Boolean

For i = 0 To ListaAccount.Size -1
    'Prelevo Ultimi 4 Caratteri
     For ii = 0 to Listaaltro.Size - 1
         if xx = "a" then Return
     Next
Next
....

When i call "Return" exit second loop but continues on the first.
Any idea ?
Thanks
Marco
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Use just "Exit" if you want to leave a For... Next... loop.

By the way: What do you want to do here? Why 2 loops?
Hi Matle the following code is an example only. I think that Erel is right. I'll have better check if there are things that recall the sub.
 
Upvote 0
Top