Control structures in cpp, C/C++ Programming

Control structures

The control structures appear in both structured programming languages as well as object oriented programming languages.  The three constructs used are:

i).  Sequence: - This is when one statement is executed following another.

ii). Selection: -It involves making a choice between at least two alternative courses of action. In C++
      there are two ways of making selections.

  • The if statements


if  (condition)


with else being optional

  • The switch statements

The following is the general format:


Case value:  ;  [-----break;]


The switch is appropriate when a number of possible states of variable have to be evaluated at


iii). Iteration: - It involves repeating a section of code, for a number of times. In C++ it is achieved in
      three ways

  • for loop
  • while loop
  • do.....while loop.

In each case, there is a condition which allows the loop to terminate.


  • The for loop:

The for loop has three principle elements:
      9  The start condition

9  The terminating condition

9  The action which takes place at the end of each iteration Syntax

for(start condition; continue condition; re-evaluation) 






The following code segment outputs the squares of numbers one to ten

for(int i=1;i<=10;i++)


cout<<"The square of:  "<


  • while loop

It is used to execute a block of statements an indefinite number of times, for zero or more number of times (i.e. pre-test loop).


while  (condition)



  • do.....while loop

It is used to execute a block of statements an indefinite number of times, for one or more number of times and will execute at least once (i.e post-test loop).





} while  (condition); 

Posted Date: 8/21/2012 11:47:24 AM | Location : United States

Related Discussions:- Control structures in cpp, Assignment Help, Ask Question on Control structures in cpp, Get Answer, Expert's Help, Control structures in cpp Discussions

Write discussion on Control structures in cpp
Your posts are moderated
Related Questions
Problem : (a) Stacks can be implemented using arrays. Write down the following C or C++ function to (i) create a stack (ii) add an element to a stack (push). (b) Expl

I need a project on car rental system using c programming only of college level

Write a C program to compute the factorial of  5 i.e. 1x2x3x4x5 etc Write a C program to calculate the output Y for a given value of X for the following formula.       Y=X 2

search words from a passage and return snippets in html format..

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Friend Functions One of the major features of OOP is information hiding. A class encapsulates data and methods to operate on that data in a single unit. The data from the class

L is a text and can be composed of any of the characters {, }, (, ) , and P, where P will represent the instruction. L will contain single spaced characters where each character

It is a feature in C++ to reduce name collisions in the global name space. This namespace keyword assigns a separate name to a library that allows other libraries to use the simila

What is the difference between structure and class? - Members of structures are public while those of a class are private. - Classes provide data hiding while structures don