how can i shyow this output using a single for loop?
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 1 2 3 4 5 6 7 8 9 10 11 12

upto
0
it can be done with two nested loops but how can i do it using a single for loop? please help me with this...

Decrement the loop counter in your loop.

yes. substring, lastIndexOf, that can help you out.

you can use while loop for your printing..and single for loop for your decrementing variable value...

hope this might be working....

that is still two loops jalpesh.
In under two minutes I've written two working ways with a single loop to do this. so yes, it is possible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.