This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Hi Belle
Posted by Kihsori Sharan on December 08, 2000 at 9:20 AM
Hi Belle You are right to some extent. In fact iteration starts with 10 , but before the control enters the for loop and checks the condition in for loop, it becomes 9. for ( int i = array.length ; --i >= 0 ; ) { // for loop body } STEPS: 1) First of all int i = array.length is executed and the variable i is initialized to 10. So the loop starts with 10. 2) Now the condition part of for loop is executed and if it has a value of true then only control will enter for loop body. --i >= 0 This part is made of two expressions viz. left hand expression --i and right hand constant expression 0 ( zero ) . Before comparing the two expressions RH and LH these two expressions will be evaluated. So first --i is evaluated and it makes the value of i equal to 9. So the condition part is 9 >= 0 for the first time which is true and then control enters the body of for loop with the value of 9 for loop variable i. I hope it is clear to you how loop variable i is changing its value. Thanx Kishori
Replies:
|