This will print "Hello!" 10 times. It's important to remember Construct 2 (and a lot of programming languages) are zero-based as a rule (however, this can get confusing when we get to Arrays, but don't worry about that just yet).
Loops in Construct 2
Most loops in Construct are system conditions. You can insert one by creating a new event, selecting 'System' and then a condition under the heading 'Loops'.
After creating a For loop, you'll be prompted for 3 fields:
Name - the name of the loop. Try to give it something descriptive, so it gives you an idea of what it's counting.
Start Index - This is the number the loop starts counting at.
End Index - This is the number the loop finishes at.
Keep in mind that both indexes are inclusive. Also, if the start index is greater than the end index, the loop will not execute.
A while loop can be made by putting a variable in either of these index fields like so:
This type of loop will execute once for each instance of an object. It is important to note that events included in this loop relating to the object specified will pick to that object. E.g. the following events will create a text object for each 'Button' sprite, move it to the button's location, and set the text to the Button's "ButtonText" variable.
It's important to note that any 'For Each' event will pick to the object it is currently counting.
The repeat event just repeats a series of events a set number of times. Note that this number can be a variable (and therefore adjusted at runtime).
Arrays In Theory
If you've ever done Euclidean geometry, you've already encountered a form of arrays in the form of the X and Y axis. An array is a set of values with distinct coordinates.
The X axis is usually referred to as 'width', the Y as 'height' and the Z as 'depth'.
Each coordinate in the array contains a value. For instance, in the array above, (1, 0) has the value "World".
Arrays in Construct 2
Arrays are an object, which means they are created like any other object by double clicking the canvas, or right clicking and selecting "Insert new object".
In Construct 2 (currently) arrays are 3 dimensional, although often they can be used as 2 dimensional or 1 dimensional. This means they have a X (width), Y (height) and Z (depth) axis.
The size of an array determines how many values it can hold in each axis. Remember when I said Construct 2 was zero-based? This is one slightly confusing thing about arrays. Size is not zero-based, but coordinates are.
Let me give you an example. An array with a width, height and depth of 1 will only have 1 location where a value can be stored. This value will be at x = 0, y = 0 and z = 0.
Depth, height and width can be changed by clicking on the array object and altering their values in the Properties panel.
You can call the size of an array with an expression:
For Each Value
This condition is a combination of what we've learned. This loop cycles through every value in the array and will perform the actions specified for each one. There's a few expressions necessary for this to work:
Current X - This will return the X coordinate of the value the loop is currently at.
Current Y - See above
Current Z - See above
CurrentValue - this will return the value at (CurrentX, CurrentY, CurrentZ)
Using these expressions in conditions and actions can let you do some pretty cool stuff.