Break and Continue

We’ve seen the break in a switch statement. It stops running the blocks of code, and simple exits out of the switch. In the same manner, if you use a break in a loop, it exits us from the loop prematurely (not by the loop condition). The continue keyword moves us to the end of…

For Loops in C++

The for loop is the counting loop of C++. It is usually designed to run a specific number of times, and then end. With it, it keeps a counter, to let you know where in the loop you are – useful when looping through an array which will look at soon enough. The general form…

The C++ Do-While Loop

The Do-While loop is similar to the while loop. It is a conditional loop, just like the while loop, running the body of the loop while the condition is met. However, the big difference is that the do-while loop is a post-test loop. That means that the body runs at least once, and then there…

The C++ While Loop

A while loop says to perform a set of operations while a condition is true. It is known as a pre-test loop, because the condition is tested before the loop is run at all, meaning the body of the loop may never run. The general form for a while loop is: Notice that the loop…

Formatting Output in C++

Setting the precision of numeric data is a little more complicated in C++ than in some other languages.First you, will need to include iomanip as a library to use some of these modifiers. A common method is to pass in stream manipulators to the stream to get numbers for format correctly. Some of the modifiers…