MarcoRome Expert Licensed User Longtime User Feb 9, 2016 #1 Hi all. I have this code: Code: Copy 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: Code: Copy 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: Feb 9, 2016
Hi all. I have this code: Code: Copy 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: Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Feb 9, 2016 #2 Return always returns from the sub. Maybe something else causes the sub to be called again. Upvote 0
KMatle Expert Licensed User Longtime User Feb 9, 2016 #3 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? Upvote 0
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?
MarcoRome Expert Licensed User Longtime User Feb 9, 2016 #4 KMatle said: 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? Click to expand... 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
KMatle said: 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? Click to expand... 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.