If we wanted something like the python else statement for a counter controlled loop in Java, what would it look like? We simply check either break or continue flags to see if either is set We simply check break variable to see if used. we check the for flag to see if loop terminated correctly Since there is no way for a loop in Java to tell you if it completed without breaks or continues, you'd need to set a boolean flag to indicate that and check it after the loop was completed.
QUESTION 8
-
If we wanted something like the python else statement for a counter controlled loop in Java, what would it look like?
We simply check either break or continue flags to see if either is set
We simply check break variable to see if used.
we check the for flag to see if loop terminated correctly
Since there is no way for a loop in Java to tell you if it completed without breaks or continues, you'd need to set a boolean flag to indicate that and check it after the loop was completed.
Given:
If we wanted something like the python else statement for a counter controlled loop in Java, what would it look like?
We simply check either break or continue flags to see if either is set |
||
We simply check break variable to see if used. |
||
we check the for flag to see if loop terminated correctly |
||
Since there is no way for a loop in Java to tell you if it completed without breaks or continues, you'd need to set a boolean flag to indicate that and check it after the loop was completed. |
Step by step
Solved in 2 steps with 1 images