• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

for() Loop

 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanku,
I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic