aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes for() Loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "for() Loop" Watch "for() Loop" New topic
Author

for() Loop

Vineela Devi
Ranch Hand

Joined: Dec 20, 2003
Posts: 191
Hai,
int i = 3; // line 1
for(; ; i++){
System.out.println(i);
}
in the above code why is tht the o/p i.e. value of i is starting from a random value though i had initalized the value of i to 3 in line 1.
also, same is the o/p i.e value of i starting from some random value with this modification also
for(int i = 3; ; i++){
System.out.println(i);
}
Also, in whatever way i try to initalize i value , o/p is starting from some random number

Anyone pls explain why it happens?
vineela
Harsha Vardhan Madiraju
Greenhorn

Joined: Dec 19, 2003
Posts: 24
hi vineela,
The O/P starts from 3 itself!
Its hard to see it on the system,
so give as
for(int i = 3; ; i++){
System.out.println(i);
if(i>30)
break;
}
Vineela Devi
Ranch Hand

Joined: Dec 20, 2003
Posts: 191
Thanku,
I got it.
 
 
subject: for() Loop