Does anyone knows what the group_skip
do?
Maybe it is a basic programming, but I've been programming using Java for some years and just found it today.
group_skip: do {
event = stepToNextEvent(FormController.STEP_OVER_GROUP);
switch (event) {
case FormEntryController.EVENT_QUESTION:
case FormEntryController.EVENT_END_OF_FORM:
break group_skip;
}
} while (event != FormEntryController.EVENT_END_OF_FORM);
Thanks!
group_skip
is a label. Labels allow you to break or continue specific loops when you've got them nested.Here's what Oracle has to say on the subject.
group_skip
is a label used for things like break. (Also goto and jump in other languages)In java specifically it would be used to break from a code block identified by the label, behaving just like a
break
statement in a while loop, except breaking from a labeled code block.Here is some more discussion on the topic
This is a labelled loop, when
break group_skip;
statement is executed, it will jump out of the do while loop which is labelled asgroup_skip
This outputs
You can get the concept clear here.
for
loop calledouter
and there is innerwhile
loopbreak outer;
statementouter for loop
has aSystem.out.println"Outer loop"
statement but that does not get printed.break outer
causes the control to jump out of labelledfor
loop directlyNow this example for
continue
statementThis prints
for
loop here and an innerfor
loopfor
loop printsHello
and continues to theouter
loop.for
loop are skipped andouter
loop continues to execute.outer
for loop,Good Bye
is printedHope this makes everything clear.
when ever we use simple break statement then we can only transfer control from inner most loop to the outer most (if we have nesting of loops). for exampel
will simply transfer the control to statement x. But if you use it inside nested loops then it will work differently.
in this case it will send the control to statement y. If you want to send the control from innermost loop to either outermost loop or outside the loop then you need such a break statements with labels. Just do it from your self and you will see interesting output.. :)