This site requires JavaScript, please enable it in your browser!
Greenfoot back
erdelf
erdelf wrote ...

2012/10/22

for loop problems

erdelf erdelf

2012/10/22

#
the following for loop is in the constructor in my world, but it isnt executed one time.
        int x= 3;
        for(int i = 0; i == x; i++)
        {
            System.out.println(i);
        }
Upupzealot Upupzealot

2012/10/22

#
For the first loop: i == x is false, so it returns with nothing done
erdelf erdelf

2012/10/22

#
thx, I always forget how loop works
Gevater_Tod4711 Gevater_Tod4711

2012/10/22

#
the first time x is 3 and i is 0. so i == x is false like Upupzealot already sad. But what do you want the loop to do? Maybe we could help you.
davmac davmac

2012/10/22

#
Perhaps you meant 'i < x'?
SPower SPower

2012/10/22

#
@erdelf, you don't understand loops apparently, so look at link.
erdelf erdelf

2012/10/22

#
yeah, when I didn't used the for loop for a while, I forget the most parts.
You need to login to post a reply.