In this lesson, we're going to talk about loops.
Looping capability is the last tool that you're going to need to add 
to your toolbox of constructs in any programming language that 
allows you to compute anything that is computable.
Again, you have input and output, you have decision branching, 
you have the capability of storing, memorizing, and modifying 
data,
and now with lopping, that is repeating a process, you can 
compute anything that actually is computable.
Now that doesn't mean that everything is computable. 
To learn more about computability you need to take more 
advanced courses in computability theory, and of course we have 
them in our department.
Okay, so what do we mean by loops? Well, as I said we are going 
to be able to create code that will repeat some process.
Now there are two kinds of loops in C++: the sentinel loops and 
the counting loops.
There are 2 sentinel loops in C++, the while statement and the 
do-while statement. They are very similar as you'll see from the 
syntax and how they actually work.
There is one counting loop. It is the for statement.
But before I get into the specific syntax of these loops in C++, I 
want to talk about loops in general and what is necessary in any 
kind of a looping structure.
You need to have what is called a loop control variable or 
perhaps more accurately, a loop control expression.
Some variable or combination of variables that's going to control 
the execution of a loop.
We'll make this simple in our examples so that we have one 
variable to deal with. We'll refer to it as the loop control variable.
In any loop, the loop control variable must go through three steps. 
Number one, the loop control variable has to be initialized, two, it 
has to be checked or evaluated, and three, it has to be updated.
If any one of these three is not included in your loop, then you're 
going to end up with a broken piece of code.
Either the loop will do absolutely nothing, or you can end up with 
the possibility of what we call an infinite loop. Meaning it's going 
to repeat the process over and over ad infinitum.
That of course is not acceptable.
How do you know if you have an infinite loop? When you execute 
the program, the cursor will hang in the screen like it's doing 
absolutely nothing.
You'll gaze at it for a few seconds and wonder well okay, I'm 
expecting such and such an output and it doesn't come.
If your program isn't doing anything within a second, then 
probably you're stuck in an infinite loop, that'll be the signal.
So how do you rescue yourself from such a situation?
Well, the way to do that is with a control-C. That is you're going to 
hit the control button and the C button at the same time. That will 
stop the process that is going on in the CPU at the time.
If by chance you have an output statement inside your infinite 
loop, then you're going to see hundreds and thousands of the 
statements coming out to the screen,
It will be scrolling off the screen like crazy. You'll think that the 
program has just gone berserk.
So, depending on the platform you're working on, you may hit 
control C and it won't stop it. 
Now the reason for that is the control C is going to stop the 
process in the CPU, but it won't stop the streaiming of the 
information to the screen.
The reason being is that output information is buffered. What 
comes from the CPU is sent into a register and held until the 
CPU thinks well its time to kick it on out to the output device.
So that may keep happening even though the processor has 
stopped its operation. If it seems like that's going to go on forever 
and ever, meaning a few minutes,
you have the option of just shutting the window down.  You'll have 
to log back in and you may have lost some updates, maybe not, 
but that's a possibility depending on what order you did things in.
So control C should be able to stop it. Now, that doesn't help you 
in solving the problem. Of course with the problem being where 
is the breakdown in logic?
The compiler is not going to find this, obviously, you wouldn't have 
run into this problem. It's a logic problem.
The easiest way I  think of that day you can find these difficulties 
is to put output statements in your code at strategic locations to 
determine how far execution has gotten.
You can write a simple output statement like this and I would 
suggest backing it up to the left hand margin of your program so 
that you can locate that statement easily.
In other words it will be out of format.
So, you'll look through your code when you're getting near done or  
after you've found the problem and you can see these output 
statements and delete them.
Another point that is really very important is this right here. I'll 
explain later the difference between using an end line and using 
the backslash "n" as you will see in some publications.
Both of them seemingly do the same thing the end line and 
backslash "n" inside the quote.  
For instance if I were to put a backslash "n" right here, what 
would happen is that will send the cursor back to the beginning 
of the next line right after the word this.
So, both of these do the same thing, but the endline has the 
added bonus that it will flush the buffer.
That way if you put an output statement in a strategic location 
you're not going to be fooled by it's late sending out to the output 
device.
That is to say, that output statement could be sent to a buffer the 
CPU go on to execute other processes, other code and get stuck 
