R rpsj Member Licensed User Longtime User Dec 14, 2012 #1 Hi ! I started a brand new project and did this : Code: Copy Sub Activity_Resume Do While True Loop End Sub Give an error : Compiling code. 0.01 Compiling layouts code. 0.00 Generating R file. 0.21 Compiling generated Java code. Error B4A line: 22 Do While True javac 1.7.0_05 src\b4a\example\main.java:240: error: unreachable statement ; ^ 1 error But if I do : Code: Copy Dim i As Boolean i = True Do While i Loop No errors !! Is this a bug or a feature ? Version 2.30 Thanks Rubens Jr.
Hi ! I started a brand new project and did this : Code: Copy Sub Activity_Resume Do While True Loop End Sub Give an error : Compiling code. 0.01 Compiling layouts code. 0.00 Generating R file. 0.21 Compiling generated Java code. Error B4A line: 22 Do While True javac 1.7.0_05 src\b4a\example\main.java:240: error: unreachable statement ; ^ 1 error But if I do : Code: Copy Dim i As Boolean i = True Do While i Loop No errors !! Is this a bug or a feature ? Version 2.30 Thanks Rubens Jr.
mc73 Well-Known Member Licensed User Longtime User Dec 14, 2012 #2 If you could explain to me what exactly is supposed to do this loop apart from looping to infinity thus crashing the os in some secs, I would reply that it's a bug. Yet, I never used a do...while without parsing a variable Upvote 0
If you could explain to me what exactly is supposed to do this loop apart from looping to infinity thus crashing the os in some secs, I would reply that it's a bug. Yet, I never used a do...while without parsing a variable
R rpsj Member Licensed User Longtime User Dec 14, 2012 #3 This was only a sample to show the bug. In my real aplication there is a IF ... then inside the loop to return from sub I spent some time to discover that was the DO While TRUE that was causing an error and not my sub ! Thanks Rubens Jr. Upvote 0
This was only a sample to show the bug. In my real aplication there is a IF ... then inside the loop to return from sub I spent some time to discover that was the DO While TRUE that was causing an error and not my sub ! Thanks Rubens Jr.
mc73 Well-Known Member Licensed User Longtime User Dec 14, 2012 #4 I have to insist on this. What was the do... while checking? True would always stand true, no question about that. This means, you wanted your sub halted. Am I correct on this? If that is so, you should simply use a boolean flag, warning all other subs to not be executed while your process inside the if... then is still running. This way, you would avoid crashing the app, due to inactivity (I have to suppose there was no doEvents statement inside this loop). Another way, would be to load a transparent panel, consuming all user interactions, while your sub was still processing data. I hope I am making clear why I insisted. Yet, everyone has his own coding preferences, no doubt about that Upvote 0
I have to insist on this. What was the do... while checking? True would always stand true, no question about that. This means, you wanted your sub halted. Am I correct on this? If that is so, you should simply use a boolean flag, warning all other subs to not be executed while your process inside the if... then is still running. This way, you would avoid crashing the app, due to inactivity (I have to suppose there was no doEvents statement inside this loop). Another way, would be to load a transparent panel, consuming all user interactions, while your sub was still processing data. I hope I am making clear why I insisted. Yet, everyone has his own coding preferences, no doubt about that
R rpsj Member Licensed User Longtime User Dec 14, 2012 #5 We are going out of scope My original question was that the statement DO WHILE TRUE gives an error in the JAVA generated code not in B4A, but when write DO WHILE some_var the error do not exist ... But, responding to your question : My sub have to read all items in a array and test some situations. I can do : Code: Copy DO WHILE xxx(i) = "some val" or xxx(i) > other_val and xxx(i) < another_val do some proc with valid data i = i + 1 LOOP or I can do Code: Copy DO WHILE TRUE if xxxx then return if xxxx and yyy then return if bla bla bla then return do some proc with the valid data i = i + 1 LOOP I think the second example is more easy to read and understand (for me of course) The array is only 1000 items and I thing that is very fast to read all. Thanks Rubens Jr. PS : Sorry, english is not my native language Upvote 0
We are going out of scope My original question was that the statement DO WHILE TRUE gives an error in the JAVA generated code not in B4A, but when write DO WHILE some_var the error do not exist ... But, responding to your question : My sub have to read all items in a array and test some situations. I can do : Code: Copy DO WHILE xxx(i) = "some val" or xxx(i) > other_val and xxx(i) < another_val do some proc with valid data i = i + 1 LOOP or I can do Code: Copy DO WHILE TRUE if xxxx then return if xxxx and yyy then return if bla bla bla then return do some proc with the valid data i = i + 1 LOOP I think the second example is more easy to read and understand (for me of course) The array is only 1000 items and I thing that is very fast to read all. Thanks Rubens Jr. PS : Sorry, english is not my native language
mc73 Well-Known Member Licensed User Longtime User Dec 14, 2012 #6 You could use Code: Copy do until xxxx or (something and yyyy) or blaBlaBla loop Upvote 0
margret Well-Known Member Licensed User Longtime User Dec 14, 2012 #7 I don't think it is a bug but that the compiler knows the condition will not change. I don't think it would change with an Exit statement in the loop but it might. mc73 has the best answer. Upvote 0
I don't think it is a bug but that the compiler knows the condition will not change. I don't think it would change with an Exit statement in the loop but it might. mc73 has the best answer.
agraham Expert Licensed User Longtime User Dec 14, 2012 #8 If you look it's a Java compiler "unreachable statement" error. The Java compiler has detected the infinite loop and errored it because it doesn't know if any statements after the loop can ever be executed. Last edited: Dec 14, 2012 Upvote 0
If you look it's a Java compiler "unreachable statement" error. The Java compiler has detected the infinite loop and errored it because it doesn't know if any statements after the loop can ever be executed.
Beja Expert Licensed User Longtime User Dec 14, 2012 #9 startit: IF xxxx OR (something AND yyyy) OR blaBlaBla THEN EXIT SUB GOTO startit Upvote 0
JonPM Well-Known Member Licensed User Longtime User Dec 14, 2012 #10 I think the OP point is that both statements are infinite loops. However, the one with the variable never errors out (like it should). Upvote 0
I think the OP point is that both statements are infinite loops. However, the one with the variable never errors out (like it should).
R rpsj Member Licensed User Longtime User Dec 14, 2012 #11 agraham said: If you look it's a Java compiler "unreachable statement" error. The Java compiler has detected the infinite loop and errored it because it doesn't know if any statements after the loop can ever be executed. Click to expand... That is the point ! Now I understood the error. If I use some var in DO WHILE xxx JAVA assume that somewhere inside the loop xxx will became FALSE and end the loop. JAVA did not saw that inside the loop has RETURN, EXIT or so .... Some C compilers do the same, but with WARNING, not ERROR ... Thanks for the help. Rubens Jr. Upvote 0
agraham said: If you look it's a Java compiler "unreachable statement" error. The Java compiler has detected the infinite loop and errored it because it doesn't know if any statements after the loop can ever be executed. Click to expand... That is the point ! Now I understood the error. If I use some var in DO WHILE xxx JAVA assume that somewhere inside the loop xxx will became FALSE and end the loop. JAVA did not saw that inside the loop has RETURN, EXIT or so .... Some C compilers do the same, but with WARNING, not ERROR ... Thanks for the help. Rubens Jr.
agraham Expert Licensed User Longtime User Dec 14, 2012 #12 JonPM said: However, the one with the variable never errors out (like it should). Click to expand... Why "should it"? You would be asking the compiler to do expression evaluation at runtime to detect assignments to that variable and predict the resulting values. The compiler can only reasonably detect uses of literals at compile time. Whether this should be treated as an error at all in Java when the compiler can only identify static cases is a matter for debate. C# for example, while similar to Java in many respects, does allow this kind of infinite loop and does not regard it as an errror. Upvote 0
JonPM said: However, the one with the variable never errors out (like it should). Click to expand... Why "should it"? You would be asking the compiler to do expression evaluation at runtime to detect assignments to that variable and predict the resulting values. The compiler can only reasonably detect uses of literals at compile time. Whether this should be treated as an error at all in Java when the compiler can only identify static cases is a matter for debate. C# for example, while similar to Java in many respects, does allow this kind of infinite loop and does not regard it as an errror.
Sortec Member Licensed User Longtime User Aug 9, 2013 #13 mc73 said: What was the do... while checking? True would always stand true, no question about that. This means, you wanted your sub halted. Am I correct on this? Click to expand... No. He just wants While True to work correctly. Its a bug. Upvote 0
mc73 said: What was the do... while checking? True would always stand true, no question about that. This means, you wanted your sub halted. Am I correct on this? Click to expand... No. He just wants While True to work correctly. Its a bug.
Erel B4X founder Staff member Licensed User Longtime User Aug 11, 2013 #15 This is an old thread. There is no reason to "bump" it. This is not a bug. The Java compiler rejects the code as it will just hang the process. There is not a single good reason for such loop. Upvote 0
This is an old thread. There is no reason to "bump" it. This is not a bug. The Java compiler rejects the code as it will just hang the process. There is not a single good reason for such loop.
nicholas.jj.taylor Member Licensed User Longtime User Aug 13, 2013 #16 Erel said: There is not a single good reason for such loop. Click to expand... I hope that you don't mind being wrong, because one excellent reason to include it is either during development of a while loop content before the condition has been developed, or during a debug to temporarily remove the condition e.g. Do While true 'BlnCondition1 = BlnCondition2 etc... Loop Still, whether you implement it or not is up to you, but that doesn't stop it from being undesirable behaviour. Last edited: Oct 2, 2013 Upvote 0
Erel said: There is not a single good reason for such loop. Click to expand... I hope that you don't mind being wrong, because one excellent reason to include it is either during development of a while loop content before the condition has been developed, or during a debug to temporarily remove the condition e.g. Do While true 'BlnCondition1 = BlnCondition2 etc... Loop Still, whether you implement it or not is up to you, but that doesn't stop it from being undesirable behaviour.