- 1

Can any Intelligent Coder explain this code to me??

https://code.sololearn.com/cTqoO2Km6x2a/?ref=app

6th Jan 2018, 8:03 AM
Puneet Thakur
Puneet Thakur - avatar
2 ответов
+ 3
well it's simple boolean done=false; if(;!done;) this is also if(;!false;) and !false is true so if(true) ++I if(i==10) done=true; so when I is 10 done is true therefore if(;!done;) and since done is true if(;!true;) where !true is false,the loop stops running
6th Jan 2018, 8:31 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
You should revisit the tutorial to understand the basics again. public class Program // Main Program class { public static void main(String[] args) // Main of the code. { int i ; // Variable i of type 'int'. boolean done = false; // a bool variable to mark the end. i = 0; // initialized i to 0. for(;!done;) // Infinite loop that runs till done is true. { System.out.println("i is " + i); // Prints i. if(i==10) done = true; // Break out of loop when i==10. i++; // Increment i for next iteration } } } // Thus, i become 0->10. // After 10, the loop stops.
6th Jan 2018, 8:29 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar