Sycrid Sycrid - 1 year ago 130
Java Question

Android based programming...loops

this may be a very simple question. I was working through a tutorial and I didn't bookmark the page so I can't go back to it.

Never the less I'm stumped by one small part of the java language which is potentially very simple but I'm new to it. What does the following mean, and can it be amended to count higher?

for(int i=c.getCount()-1; i>=0; i--)

I believe it's an integer counter, which assigns a the value of c.getCount to i, then subtracts one, makes i equal nothing and then adds 1 to i again... is this right? I need to increase this beyond one, so is that possible.

Answer Source

This is a for loop of decrement!

Here the value of i would be initialized to c.getCount()-1

And then it checks if that is greater than or equal to zero and gets in to the loop.

After executing the loop contents, i count is decremented to 1. i--

And then again checks for the condition and runs the loop. The loop runs until the i value becomes lesser than 0.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download