Was doing some Java practices and one particular for loop pattern confused me. I was working towards a goal to print this pattern,
123456
12345
1234
123
12
1
And the solution given was
for(int k = 8; k > 1; k--) {
for(int l = 1; l < k - 1; l++){
System.out.print(l);
}
System.out.println();
}
I played with the values but I didn't understand the value of k = 8. wouldn't that mean the loop runs 7 times when k > 1 is true?
edit I played around with the code and found out a lesser, more simplified code that made more sense to me,
for(int k = 6; k >= 0; k--) {
for(int l = 1; l < k; l++){
System.out.print(l);
}
System.out.println();
}
It too gave me the same outcome. Is this way of logic more confusing to people or is it easier to understand?