+ 3
How does it work. For(int i = 2; i<10; i=i*i)
Based on java language
2 Answers
+ 1
for(int i = 2; i<10; i=i*i)
System.out.println (i);
//Now you understood?
0
Ndeleche Hamis Ndeleche
int i=2 //is initialization which executives once at first time , then
i<10 //condition will evaluate if it's true then body of loop will evaluated else next next statement followed by for loop
i=i*i //increments when body of loop executed , after that again condition will be checked if true then body executed else next statement !
Here for(i=2;i<10;i=i*i)
i=2 , than condition will be checked which evaluates to true then it goes in body executes your body statements , then it increments " i "
to i*i. Hence i=4 Again condition checked which assigns is true then goes in body , again value of I increments to i=4*4=16 , here condition will checked which is false , hence it goes out of loop!