control structures in c++

12
CONTROL STRUCTURE IN C++ PREPARED BY:- NITIN KUMAR

Upload: nitin-jawla

Post on 23-Jan-2017

330 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Control structures in c++

CONTROL STRUCTURE IN C++

PREPARED BY:-NITIN KUMAR

Page 2: Control structures in c++

Control StructuresControl structures are used to affect how

statements are executed.

Three Control Structures Are:-

Sequence structure (Straight line)Selection structure (Branching)Loop structure (Iteration or repetition)

Page 3: Control structures in c++

Sequence StructureStatements are executed one after the other.This is C++'s default behavior!

Sequence Example:-

Page 4: Control structures in c++

Selection StructureUsed to choose among alternative courses of action.Making decisions

Three selection structures are:-•If

•if/else

•switch

Page 5: Control structures in c++

If selection structureUsed to do something if some condition is

“true”.if syntax:-

Page 6: Control structures in c++

If/else selection structureUsed to do one thing if some condition is

“true”, something else if the condition is “false”.

if/else syntax:-

Page 7: Control structures in c++

Switch Selection structureThis is a multiple-Branching Statement where

based on a condition the control is transferred to one of the many possible points. Switch case Example:-

Page 8: Control structures in c++

Loop structureUsed to repeat a set of instructions.Looping

There are three selection structures available in C++:-•Do-While

•While

•For

Page 9: Control structures in c++

Do-While Loop structureThe do-while is an exit-controlled loop . based

on a condition the control is transferred back to a particular point in the program.

Do-While Example:-

Page 10: Control structures in c++

While Loop structureThe while loop is an entry-controlled loop .

While Example:-

Page 11: Control structures in c++

For Loop structureThe For is an entry-controlled loop and is

used when an action is to be repeated for a predetermined number of times.For Example:-

Page 12: Control structures in c++

THANK YOU