hi all,
i have a sub
I want to return the value of i when the condition is correct.
If I write like this, it always returns a value of -1
If I write like this, the continuation of the code will not run (Because Return) and the 'for' will run again.
i have a sub
I want to return the value of i when the condition is correct.
If I write like this, it always returns a value of -1
B4X:
Sub getidlist(us As List,user As String) As Int
For i = 0 To us.Size-1
Dim map As Map = us.Get(i)
If map.Get("UserName").As(String) = user Then ' If the condition is correct, I want to exit the sub and return the value of i
Exit '***
Return i '***
End If
Next
Return -1
End Sub
If I write like this, the continuation of the code will not run (Because Return) and the 'for' will run again.
B4X:
Sub getidlist(us As List,user As String) As Int
For i = 0 To us.Size-1
Dim map As Map = us.Get(i)
If map.Get("UserName").As(String) = user Then 'If the condition is correct, I want to exit the sub and return the value of i
Return i '***
Exit '***
End If
Next
Return -1
End Sub
Last edited: