control structures in c++
TRANSCRIPT
![Page 1: Control structures in c++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/1.jpg)
CONTROL STRUCTURE IN C++
PREPARED BY:-NITIN KUMAR
![Page 2: Control structures in c++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/2.jpg)
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++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/3.jpg)
Sequence StructureStatements are executed one after the other.This is C++'s default behavior!
Sequence Example:-
![Page 4: Control structures in c++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/4.jpg)
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++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/5.jpg)
If selection structureUsed to do something if some condition is
“true”.if syntax:-
![Page 6: Control structures in c++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/6.jpg)
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++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/7.jpg)
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++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/8.jpg)
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++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/9.jpg)
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++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/10.jpg)
While Loop structureThe while loop is an entry-controlled loop .
While Example:-
![Page 11: Control structures in c++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/11.jpg)
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++](https://reader035.vdocuments.net/reader035/viewer/2022070513/58858d8c1a28ab84668b6653/html5/thumbnails/12.jpg)
THANK YOU