B4J Question Unreachable statement failed to compile.

stevel05

Expert
Licensed User
Longtime User
I had a good one today, making changes to an existing project I replaced an inner for loop with a do while true and got the error:

B4X:
B4J Version: 10.20 BETA #3
Parsing code.    (0.01s)
    Java Version: 19
Building folders structure.    (0.01s)
Compiling code.    (0.01s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Compiling generated Java code.    Error
B4J line: 31
Do While True
src\b4j\example\main.java:133: error: unreachable statement
;
^
1 error

I created a new app and copied the whole sub, and all of it's dependencies, there were quite a few. Then started deleting blocks of code. There were about 100 lines of code inside the Do While loop, so didn't notice until I stripped it all down that I had neglected to put an exit in the inner Do while loop

What it boils down to is that I had this:

B4X:
Private Sub test
    For i = 1 To 10
 
        Do While True
     
        Loop
 
    Next
End Sub

Which throws the exception above on compilation.

There was no Exit clause which I couldn't see in amongst the rest of the code. Now I know what the problem was the error message sort of makes sense, but I thought it was a bit cryptic at first.
@Erel I will remember this one in future but I don't know if it's possible to catch this situation in the IDE validation, it may be worth it if it is.
 
Last edited:
Top