Control structures in cpp, C/C++ Programming

Assignment Help:

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

Syntax

if  (condition)
      -----

else

with else being optional

  • The switch statements

The following is the general format:

switch(variable|value)
{

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

}

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

 

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) 

 

{

Statement(s);

}

Example:

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).

Syntax

while  (condition)
{

Statement(s);

}

  • 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).

Syntax

do

{

Statement(s);

} while  (condition); 


Related Discussions:- Control structures in cpp

I need cryengine sandbox speedometer and tachometer, I need Cryengine Sandb...

I need Cryengine Sandbox Speedometer and Tachometer We want to get working Tachometer and Speedometer for a car in latest Cryengine Sandbox. You will find how to make it usin

Time table, programme for time table in c++

programme for time table in c++

Explain difference between early binding and late binding, What is the diff...

What is the difference between early binding and late binding? What are advantages of early binding? a.) Late binding refers to function calls which aren't resolved until run t

Implement mini version of linux ''tar'', I need to implement a mini version...

I need to implement a mini version of linux''s ''tar'' function in C.

Friend funtion.., Is friend function can be harmfull to make a secure progr...

Is friend function can be harmfull to make a secure program/sofware?

Explain the declaration of multi dimensional arrays, Explain the Declaratio...

Explain the Declaration of Multi Dimensional Arrays? In the figure, the range in the first dimension is 3 and in the second dimension is 4. The shaded portion corresponds to th

Optimized nic driver for windows compact 7, Optimized NIC Driver for Window...

Optimized NIC Driver for Windows Compact 7 for Hard Real Time Communication Project Description: I am seeking an optimized driver (miniport driver) that will be used for sele

What is class definition, Class Definition The following is the general...

Class Definition The following is the general format of defining a class template: class tag_name                  {                    public  :               // Must

Need discrete math tutor, Project Description: I will need a tutor that ...

Project Description: I will need a tutor that would help me out in Data Structure and learning Algorithm more at the mathematical/algorithmic level. The book is written by "by T

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd