How does it work. For(int i = 2; i<10; i=i*i) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How does it work. For(int i = 2; i<10; i=i*i)

Based on java language

5th May 2021, 7:58 PM
Ndeleche Hamis
Ndeleche Hamis - avatar
2 Answers
+ 1
for(int i = 2; i<10; i=i*i) System.out.println (i); //Now you understood?
5th May 2021, 8:31 PM
Atul [Inactive]
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!
6th May 2021, 1:05 AM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar