I'll assume you're referring to the example of a for loop, but in future, post the code you're referring to, and you'll definitely get a better response with more specific questions.
Loops are just tools to make it easier on you when you have a bunch of very similar tasks that need to be repeated over. Like if you have a list of numbers, and you need to add 1 to each number - you would use a loop.
For loops are structured like this:
Code:
for (starting values; test conditions; increments)
{
// Code
}
The most important part of the loop is the first line - the word 'for' followed by a set of parentheses. Inside the parentheses are 3 sections, separated by semicolons (as shown).
The first section is your starting values. In most loops, you will need a counter or some number to help you control the loop (keep track of how many time the loop has cycled, etc...). In this sections you can declare new variable, assign values to variables, etc... If you need to initialize mroe than one variable, just put your statements between commas, like this:
Code:
for(int i = 0, j = 9; ...
In the second section you have your test conditions. You need to tell your loop when to stop repeating the action you tell it to do. Let's say that the variable we declared earlier, ' i , (i is commonly used as a counter in loops), is being used as a counter. We want the loop to execute 10 times, so we set i equal to 0 at the start, and tell the loop to keep executing as long as i is less than 10. In your second section, put all the conditions (separated) by commas that must be true for the loop to keep executing. So in our example, i must be less than 10.
Code:
for ( int i = 0, j = 9; i < 10; ...
Now if you're counting the number of times the loop has executed, you want the counter variable to go up by one each time. In the third section, you can list all the changes you want made to variables. I don't know if you've learned this yet, but in C++, since adding 1 to a number is a very common thing, you can just write "i++" and i will go up by one.
Code:
for ( int i = 0, j= 9; i < 10; i++)
The variable j really has no purpose in our loop, it's just there to demonstrate the use of commas. If your loop is just repeating one line of code, you don't need to use braces, but if it's a section of code, you need to separate it from the rest of your program.
Code:
for ( int i = 0, j= 9; i < 10; i++)
{
// Put your code here
}
When you learn about arrays, loops will become very useful to you. If needed, you can use the i and j variable inside your code. One final piece of advice: make sure you DO NOT put a semicolon between your closing parenthesis and your opening brace. That's a common mistake, and it will cause your loop do to pretty much nothing.
I hope that helps.