java - Different for-loop incremental value -


i fiddled around loops, , tried head around of logical part of it. while i'm far beyond level of loops @ point, still tend bit weird when comes logic sometimes.

however, found incremental value of loop different depending on whether inside or outside loop:

int i; for(i = 0; < 10; i++) {    system.out.println(i); // 0 ... 9 }  system.out.println(i); // 10 

now, i'm afraid 1 day i'll come point i'll have use counter more matching against condition...

now think understand why happening; being incremented after condition fails , loop dies, supposed happen?

is there mathematical/logical (or elegant) way not make go n+1 after loop termination, i'm missing here?

that how loop works:

  1. check condition, if holds go 2, else terminate;
  2. run body;
  3. execute modification, go 1.

so in word, cannot.

also, how loop terminate if variable not go n + 1? in case, loop condition holds, run forever.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -