Presentation on.C++ loops and its types .pptx

ksami9309 9 views 9 slides Oct 02, 2024
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

Presentation on C++ loops


Slide Content

TOPIC TRANSFER OF CONTROL 1)IF Else statement 2)Switch statement

Transfer of control In C++, transfer of control refer to the mechanism that alter the normal flow of program execution. These mechanism transfer control to another part of the program , bypassing the normal sequential execution. Following statements are used to change the normal flow of execution of statement of program. If statement If else statement Switch statement Loop statement

C++ IF-else Statement The C++ if-else statement also tests the condition. It executes if block, if condition is true otherwise else block is executed. EXAMPLE: #include <iostream> using namespace std; int main () { int num; cout <<”\n Enter value for Num….”; cin >>num; if (num == 500) {

cout <<“HELLO"; } else { cout <<"Bye bye "; } return 0; } EXAMPLE 2 #Include<iostream> Using namespace std; Int main() { int numbers; Cout <<“ enter marks”;

cin >>marks; If(marks>=90&& marks <= 100) Cout <<“grade A”; Else if (marks>=80&&marks<90) Cout <<“grade A”; Else if (marks>=70&&marks<80) Cout <<“grade B”; Else if( markd >=60&&marks<70) Cout <<“grade C”; Else if (marks>=50&&marks<60) Cout <<“grade D”;

Else if (marks>=0&&marks<50) Cout <<“grade F”; Else cout <<invalid marks; return 0; }

C++ switch: the c++ switch statement is a control flow mechanism that allows executing different blocks of code based on the value of an expression. RULES: Expression must be an integer Case value must be constatnt No duplicate value Default case is optional. Example : #include<iostream> using namespace std; // program for switch statement... int main() { int n;

{ int n; cout <<"Enter any number, 1 to 3"<< endl ; cin >>n; switch(n) { case 1: cout <<"\n One Pressed"; break; case 2: cout <<"\n Two Pressed"; break; case 3: cout <<"\n Three Pressed"; break; default: cout <<"\n not in range";

} return 0; } THANK YOU
Tags