In this tutorial you will learn about the C++ Control Flow Statements and its application with practical example.
C++ Control Flow Statements
Control flow or flow of control is the order in which instructions, statements and function calls being executed or evaluated when a program is running. The control flow statements are also called as Flow Control Statements. In C++, statements inside your code are generally executed sequentially from top to bottom, in the order that they appear. It is not always the case your program statements to be executed straightforward one after another sequentially, you may require to execute or skip certain set of instructions based on condition, jump to another statements, or execute a set of statements repeatedly. In C++, control flow statements are used to alter, redirect, or to control the flow of program execution based on the application logic.
C++ Control Flow Statement Types
In C++, Control flow statements are mainly categorized in following types –
C++ Selection Statements
In C++, Selection statements allow you to control the flow of the program during run time on the basis of the outcome of an expression or state of a variable. Selection statements are also referred to as Decision making statements. Selection statements evaluates single or multiple test expressions which results in “TRUE” or “FALSE”. The outcome of the test expression/condition helps to determine which block of statement(s) to executed if the condition is “TRUE” or “FALSE” otherwise.
In C++, we have following selection statements –
C++ Iteration Statements
In C++, Iteration statements are used to execute the block of code repeatedly for a specified number of times or until it meets a specified condition. Iteration statements are commonly known as loops or looping statements.
In C++, we have following iteration statements available-
C++ Jump Statements
Jump statements are used to alter or transfer the control to other section or statements in your program from the current section.
In C++, we have following types of jump statements –
All of the above jump statements cause different types of jumps.