C++ Tutorials: Loops
In this tutorial we will be covering loops. This is going to be a shorter tutorial then all the others but much more necessary.
A loop is a a something that repeats until a condition is met or infinitely. There are two kinds of loops:
For
and
While
While is more common but they are both used a lot.
They look like this:
Those two pieces of code are effectivly the same. The for loop looks better doesn't it? Well for loops are generally used for that type of thing,
While loops though are used where for loops look bad like so:
These two pieces of code are the same, they are both repeat indefinitely. the while loop looks better right?
so here is a good example:
Now there is one special thing before we move on to the next tutorial:
endl
endl means end line and is defined as char endl = "n";
so you can either use endl or n
In the Next tutorial we will be discussing input. We will also be discussing special types such as cerr.
In this tutorial we will be covering loops. This is going to be a shorter tutorial then all the others but much more necessary.
A loop is a a something that repeats until a condition is met or infinitely. There are two kinds of loops:
For
and
While
While is more common but they are both used a lot.
They look like this:
Code
Those two pieces of code are effectivly the same. The for loop looks better doesn't it? Well for loops are generally used for that type of thing,
While loops though are used where for loops look bad like so:
Code
These two pieces of code are the same, they are both repeat indefinitely. the while loop looks better right?
so here is a good example:
Code
Now there is one special thing before we move on to the next tutorial:
endl
endl means end line and is defined as char endl = "n";
so you can either use endl or n
In the Next tutorial we will be discussing input. We will also be discussing special types such as cerr.
No comments:
Post a Comment