Mustang Bulton

Greenhorn
+ Follow
since Feb 01, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mustang Bulton

Ahhhhhhh thanks people

I really thought more than 1 hour about that. Didn't know that the inner loop resets each time.

Best regards,
M
14 years ago
Hello everyone.

I am learning Java at the moment and I have problems to understand connected for-loops.
Let me explain what I mean by some quite easy example:



The outcome is simple as that:


Ok so my thoughts are these:

- first check if 1 < 3. That's true, enter the instructions in the inner loop
- check if j <= i, meaning 1 <= 1. True, print out one Star *.
- finished instructions in the inner loop, so next step is j++, meaning j = 2.
- check if j <= i, meaning 2 <= 1. That's wrong, the inner loop is done.
- print out new line
- outer loop: i++ (must be increased). Then i = 2 = j.

- ok, now enter outer loop again (condition true)
- inner loop: j <= i, meaning 2 <=2 = true.
- =>=>=> print ONE Star *.

I don't understand, why it prints 2 Stars at that point. Any help would be highly appreciated
14 years ago