Hello
How can achieving this code using B4X syntax (without select case, if or other solutions):
I mean how to implement label with break in B4X.
Or in another explanation, How did these in B4X:
How can achieving this code using B4X syntax (without select case, if or other solutions):
Java Labeling:
// Java code to illustrate
// using label and break
// instead of goto
// label for outer loop
outer:
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j == 1)
break outer;
System.out.println(" value of j = " + j);
}
} // end of outer loop
// output is:
// value of j = 0
Or in another explanation, How did these in B4X:
Java:
outer: // Should be placed exactly before the loop
loopingConstructOne { // We can have statements before the outer but not inbetween the label and the loop
inner:
loopingConstructTwo {
continue; // This goes to the top of loopingConstructTwo and continue.
break; // This breaks out of loopingConstructTwo.
continue outer; // This goes to the outer label and reenters loopingConstructOne.
break outer; // This breaks out of the loopingConstructOne.
continue inner; // This will behave similar to continue.
break inner; // This will behave similar to break.
}
}
Last edited: