It's not a secret anymore!
The moose likes Beginning Java and the fly likes for-loop weird thing. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "for-loop weird thing." Watch "for-loop weird thing." New topic

for-loop weird thing.

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
I found something weird.

Why nothing output ? I think it should display "index=1".

Any help ?

marc weber

Joined: Aug 31, 2004
Posts: 11343

In the for loop, the boolean condition evaluates to false on the first try (when i is zero) because dddd does not contain "0". Therefore, the loop body never executes, and i is never incremented to 1.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: for-loop weird thing.
It's not a secret anymore!