-1

After a lot of 'ArrayIndexOutOfBound' messages, this for-loop works for me, but only because I compensated with (i-1).

Doesn't --i(t) means: _before entering the loop, decrement by one?

for (int i = offset; i > 0; --i) {
    if (Character.isLetter(lnCmplt.charAt(i - 1))) {
      selStart -= 1;
      Log.i("1.for (i-1)= ", (i-1)+" char=["+lnCmplt.charAt(i-1)+"] selStart= "+selStart);
    }
}

Log.i console output (it is real, only trimmed):

lnStart= 492 lnEnd= 506 offset= 7 // from Log line before

I/1.for (i-1)= 6 char=[e] selStart= 6 //<-- this value has to be 5 (i=7 ; --i (=6) ; i-1 (=5)

I/1.for (i-1)= 5 char=[k] selStart= 5 ...

[Edit] Solution: On first loop the x-crement isn't executed.

uneviltoo
  • 21
  • 4

1 Answers1

1

It's not a crazy idea, but no, it doesn't.

--i is executed before the rest of the statement, but it doesn't change when the statement is executed.

So it will work here:

int i = 0;
System.out.println(--i);

But in a for loop construct it is completely equivalent to using i--.

wvdz
  • 16,251
  • 4
  • 53
  • 90