Actually, this is the first time I see a code like this:
class A
{
public static void main(String args[])
{
outer : for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(j > i)
{
System.out.println();
continue outer;
}
System.out.print(" " +( i *j ));
}
}
System.out.println();
}
}
two lines I don't understand:
outer : for(int i=0;i<10;i++) // this seems similar to 'for each'?
continue outer; // I know that 'continue' will break the loop and continue the next turn, but what will do in this situaton?
Denigma - AI that reads and explains code in understandable english.
“Coding is hard because it's different” Coding is thought to be hard because it's a different type of skill; and “different” in the sense that it's unlike anything most of us have ever experienced before.
This 4 step process is simple and will save you a lot of time and effort; all you need to do is: Run the code and explore the results. Find the main function or the start point of the code. Run the code under the debugger and fully understand the code's mechanics.
The outer:
part is a label. It's basically labelling the loop. The loop itself works just as normal.
The continue outer;
means "continue back to the start of the body of the loop labelled outer
" (after incrementing and testing i
of course). It's sort of like having a break;
statement to get out of the inner loop, and then immediately having a normal continue;
statement to continue with the next step of the outer loop.
outer : for(int i=0;i<10;i++)
defines a label for the outer loop, called outer
continue outer;
means, go to next iteration of the loop labeled outer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With