Thanks Myklos,
I did research and I found this "If we have a for loop inside another loop, the inner loop executes completely whenever outer loop executes."
Based on this I rebuild the flow for this nested flow and got this:
-1st iteration: a=1 , condition met as 1<= 4, so is true, flow go to next "for" loop: x=a, x<=c, true, print 1a; x++ that is x=b;
x = b;x <=c, true, but x==b will activate the continue statement as the if statement will return true, which will transfer the control to boolean expression for inner loop than nothing to print and x
will be x++ that is x=c;
x = c ; x<=c, true, print 1c, x++ is d
x=d; x<=c is false, end of iteration;
a = a+1= 2 ( end of first iteration)
-2nd iteration: a=2, a<=4, true, x=a, x<=c, true, but a=2 will activate the continue statement as the if statement will return true, which will transfer the control to boolean expression for inner loop, nothing to print, and whole inner loop will not be printed as ||(OR short circuit operator) operator will be evaluated true no matter what will be the x value;
a will became a++ , that is a=3 ( end of second iteration);
- 3rd iteration: a=3, a<=4 is true, next "for"loop, x=a, x<=c, true, print 3a; x++ that is x=b;
x=b, x <=c, true, but x==b will activate the continue statement as the if statement will return true, which will transfer the control to boolean expression for inner loop, nothing to print, and x will be x++ that
is x=c;
x = c ; x<=c, true, print 3c,x++ is d
x=d; x<=c is false, end of iteration;
a = a+1= 4 ( end of third iteration);
- 4th iteration: a=4, a<=4 is true, next "for"loop, x=a, x<=c, true, print 4a; x++ that is x=b;
x=b, x <=c, true, but x==b will activate the continue statement, which will transfer the control to boolean expression for inner loop, nothing to print, and x will be x++ that is x=c;
x = c ; x<=c, true, print 4c, x++ is d
x=d; x<=c is false, end of iteration;
a++ that is a=5 (end of 4th iteration);
- 5th iteration: a=5, a<=4, false, loop skipt (end).
The main point I took from here is this "the inner loop executes completely whenever outer loop executes." Now here the completely part will not apply as the if statement will stop the flow on certain conditions.Love Java ..pffff Lol
Not sure if my logic flow is right here, I think so, but hopefully this will help other novices like me to get the basics right.
All the best!