# Loops...for etc

Just started using Construct 2? Post your questions here

### » Thu Jan 08, 2015 12:57 pm

I am just trying to create a simple loop

for a = 1 to 10
print a
next

Have looked in the forum but I am none the wiser

have attached the .capx file, and any help appreciated

Thanks
You do not have the required permissions to view the files attached to this post.
B
8
S
1
Posts: 9
Reputation: 487

### » Thu Jan 08, 2015 1:10 pm

You are repeating the loop infinitely, since you added no other condition. If you want the loop to happen once every 1 second, the loop MUST be nested under the Every 1 seconds event. In this case the variable will increase 10 every 1 second.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 4,006

### » Thu Jan 08, 2015 3:29 pm

Bruno thanks for the reply, yes sorry my mistake, but why does it increment by 10 when I do as you suggested.

Do for loops not work the same as in for example Python, where from my above code the loop would count from 1 to 10, using the loop as the counter?
B
8
S
1
Posts: 9
Reputation: 487

### » Thu Jan 08, 2015 3:43 pm

Maybe you want to counting from 1 to 10? Then this is what I did:
B
126
S
54
G
24
Posts: 795
Reputation: 24,123

### » Thu Jan 08, 2015 5:52 pm

Because you add 1 every loop iteration. The loop has 10 of those iterations every second, thus, every second it adds 1 to the the variable 10 times. That's why it goes in increments of 10.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 4,006

### » Thu Jan 08, 2015 8:00 pm

Many thanks to you both, I now have a little better idea about loops. Now just to experiment with them!!
B
8
S
1
Posts: 9
Reputation: 487