This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes for() Loop Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: for() Loop
 
Similar Threads
Operators
Math.round...(for -ve no.)
The i++ operator
Need definitions of nextInt(), abs() and some other questions