C++ Control Statements

What is Control Statements in C++?

 A C++ Control Structures are statements that change the flow of a program to a different code segment based on certain conditions. The control structures are categorized into three major Conditional types they are Selection Statements, Iteration statements, Jump Statements.

Selection Statements

If Statement
If statements allow the program to execute different blocks of code depending on conditionals.If statement executes the code in the body section if the condition evaluates to True, otherwise it skips the body and An Else statement acts as a default case for If statements.
For more detail Click here 


Else Statement
If is directly followed by an Else and the condition is false, the code in the Else is executed. Else statements do not have a condition themselves.
For more detail Click here 


 Else-If Statement
An If statement can followed by any number of Else-if blocks. Each Else-if has its own conditional statement and body of code. If an Else-if conditional is False, then its body of code is skipped and the program will check the next Else-if in order that they appear. An If followed by a long list of Else-IF's is usually referred to as an If-Else ladder.
For more detail Click here 

Iteration Statements


For Loop
A for loop allows for a block of code to be executed until a conditional becomes false. For loops are usually used when a block of code needs to executed a fixed number of times. 
For more detail Click here 

While Loop
A while loop is a simple loop that will run the same code over and over as long as a given conditional is true. The condition is checked at the beginning of each run through the loop ( including the first one ). If the conditional is false for the beginning, the while loop will be skipped all together.
For more detail Click here 

Do-while Loop
A do-while loop acts just like a while loop, except the condition is checked at the end of each pass through the loop body. This means a do-while loop will execute at least once.
For more detail Click here 

                                              Jump Statements


Break
Break is a useful keyword that allows the program to exit a loop or switch statement before the expected end of a that code block. This is useful in error checking or if the outcome of a loop is not certain. For example, the following code will break out of the for loop if a user asks to leave.
For more detail Click here