- 1
Can any Intelligent Coder explain this code to me??
2 odpowiedzi
+ 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
+ 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.