- C++ Programming Basics
- C++ Tutorial
- C++ Environment Setup
- C++ Character Set
- C++ Keywords
- C++ Identifiers
- C++ Constants
- C++ Punctuators
- C++ Program Structure
- C++ Basic Syntax
- C++ Comments
- C++ Basic Programs
- C++ Input Output Operator
- C++ Input Output Stream
- C++ Type & Variable
- C++ Data Types
- C++ Data Type Modifiers
- C++ Variables
- C++ Variable Types
- C++ Variable Scope
- C++ Storage Classes
- C++ Formatting Output
- C++ Operators
- C++ Operators
- C++ Type Conversion
- C++ Numbers
- C++ Assignment Operator
- C++ Shorthand
- C++ Flow of Control
- C++ Statements
- C++ Flow Control
- C++ Decision Making
- C++ if if-else if-else-if switch
- C++ Loops
- C++ for while do-while Loop
- C++ break continue goto
- C++ Standard Library
- C++ Standard Library
- C++ Header Files
- C++ Character String
- C++ Mathematical Functions
- C++ Functions
- C++ Functions
- C++ Function Types
- C++ Function Prototype
- C++ Function Call
- C++ Function Return
- C++ Friend Function
- C++ Scope Rules
- C++ Arrays & Strings
- C++ Arrays
- C++ One Dimensional Arrays
- C++ Two Dimensional Arrays
- C++ Strings
- C++ Data Structure
- C++ Data Structure
- C++ Access Structure Member
- C++ Nested Data Structure
- C++ Structure Array
- C++ Pass Structure to Function
- C++ typedef
- C++ #define
- C++ Programming Pointers
- C++ Pointers
- C++ Memory Map
- C++ Free Store
- C++ Declare Initialize Pointers
- C++ Dynamic Memory Allocation
- C++ Pointers & Arrays
- C++ Pointers & Const
- C++ Pointers & Functions
- C++ Pointers & Structures
- C++ Objects as Function Arguments
- C++ Pointers & Objects
- C++ References
- C++ File Handling
- C++ File Handling
- C++ File Streams
- C++ Data Files
- C++ Opening & Closing Files
- C++ Steps to Process Files
- C++ Change Stream Behaviour
- C++ Sequential I/O Operations
- C++ Detecting EOF
- C++ File Pointers Random Access
- C++ Binary Files Operations
- C++ Error Handling
- C++ Object Oriented
- C++ Object Oriented
- C++ Function Overloading
- C++ Classes & Objects
- C++ Constructors & Destructors
- C++ Inheritance
- C++ Encapsulation
- C++ Polymorphism
- C++ Data Abstraction
- C++ Interfaces
- C++ Programming Advance
- C++ Linked Lists
- C++ Stacks
- C++ Queues
- C++ Date Time
- C++ Preprocessors
- C++ Exception Handling
- C++ Namespaces
- C++ Dynamic Memory
- C++ Multithreading
- C++ Templates
- C++ Signal Handling
- C++ Web Programming
- C++ Programming Examples
- C++ Programming Examples
- C++ Programming Test
- C++ Programming Test
- Give Online Test
- All Test List
C++ Flow Control
Generally a program executes its statements from beginning to end. But not many programs executes all their statements in strict order from beginning to end. Most programs decide what to do in response to changing circumstances. These programs not only store data but they also manipulate data in terms of consolidation, rearranging, modifying data.
To perform their manipulative miracles, programs need tools for performing repetitive statements to attain so. Such statements are called program control statements.
In a program, statement may be executed sequentially, selectively or iteratively. Every programming language provides constructs to support sequence, selection or iteration. Let's discuss what is means by sequence, selection or iteration constructs.
Sequence Construct
The sequence construct means the statements are being executed sequentially. This represent the default flow of control. Every C++ program begins with the first statement of main(). Each statement in turn is executed (sequence construct). When the final statement of main() is executed, the program is done. This construct specifies the normal flow of control in a program and is the simplest one.
Note - In C++, the program execution starts with the first statement of main() and ends with the last statement of main(). Therefore, the main() is also called driver function as it drives the program.
Selection Construct - Decision
The selection construct means the execution of statement(s) depending upon a condition-test. If a condition evaluates to true, a course-of-action (a set of statements) is followed otherwise another course-of-action (a different set of statements) if followed. This construct (selection construct) is also called decision construct because it helps in making decision about which set-of-statements is to be executed. You will learn in detail about this topic in the following two separate chapters:
Iteration Construct - Looping
The iteration construct means repetition of a set-of-statements depending upon a condition-text. Till the time a condition is true (or false depending upon the loop), a set-of-statements are repeated again and again. As soon as the condition becomes false (or true), the repetition stops. The iteration construct is also called looping construct.
The set-of-statements that are repeated again and again is called as body of the loop. The condition on which the execution or exit of the loop depends is called the exit condition or test-condition. You will learn in detail about this topic in the following two separate chapters:
« Previous Tutorial Next Tutorial »