I've recently encountered some code that was not executing as expected and narrowed it down to a 'Continue' statement. I have had to rewrite two affected code blocks to remove the Continue statement but, this is not always the ideal solution.
The issue found is that the Continue statement does not skip the remaining code within the loop (so far, all loop types are affected by this) if it is itself inside a Select block but, this behaviour is not consistent throughout the rest of the project. ie. it works as expected in some functions but not in others.
I haven't been able to reliably reproduce the issue using a small project but, I have provided one of the affected code blocks below as it is AFTER commenting out the Continue statement and applying a work around.
What's also interesting is that the expected behaviour of intellisense appears to replicate this. ie. The background colour of the corresponding loop associated with the Continue statement is changed when the expected behaviour works but, does not change when the expected behaviour does not work.
If the Continue statement is moved outside of the Select block then it works as expected.
Due to the nature of this project I cannot zip it up and attach it here.
The issue found is that the Continue statement does not skip the remaining code within the loop (so far, all loop types are affected by this) if it is itself inside a Select block but, this behaviour is not consistent throughout the rest of the project. ie. it works as expected in some functions but not in others.
I haven't been able to reliably reproduce the issue using a small project but, I have provided one of the affected code blocks below as it is AFTER commenting out the Continue statement and applying a work around.
What's also interesting is that the expected behaviour of intellisense appears to replicate this. ie. The background colour of the corresponding loop associated with the Continue statement is changed when the expected behaviour works but, does not change when the expected behaviour does not work.
If the Continue statement is moved outside of the Select block then it works as expected.
Due to the nature of this project I cannot zip it up and attach it here.
B4X:
Do While Not(IsValid)
Wait For (mainDialog.ShowCustom(pnlPrefs, obOK, "", obCancel)) Complete (dlgResult As Int)
Select dlgResult
Case DialogResponse.POSITIVE
' Validate the accepted values
IsValid = True
Dim tDistance As Int
Try
tDistance = txtPrefAutoCollectionDistance.Text
If tDistance < Starter.MinDistance Or tDistance > Starter.MaxDistance Then
' The range is outside the min/max - let the user know
UI.ShowToastMessage(obInvalidDistance, True, UI.TOAST_ERROR, UI.ICON_ERROR)
IsValid = False
' Continue ' <<<<<<<< not working as expected
End If
Catch
Log(LastException)
End Try
Dim tTime As Int
If IsValid Then
Try
tTime = txtPrefAutoCollectionTime.Text
If tTime < Starter.MinTime Or tTime > Starter.MaxTime Then
' The range is outside of the min/max - let the user know
UI.ShowToastMessage(obInvalidTime, True, UI.TOAST_ERROR, UI.ICON_ERROR)
IsValid = False
End If
Catch
Log(LastException)
End Try
End If
If IsValid Then
' Save the new values
Starter.AppConfig.Put(Starter.obAutoCollectionDistance, tDistance)
Starter.AppConfig.Put(Starter.obAutoCollectionTime, tTime)
' all is good - make the user feel all warm and fuzzy
UI.ShowToastMessage(obUpdatedPreferences, True, UI.TOAST_SUCCESS, UI.ICON_TICK)
End If
Case Else
' Cancellation from the user is Valid - nothing is updated
IsValid = True
End Select
Loop