PPS Lab PPT
PPS Lab PPT
SwitchCaseStatement
Bachelor of Technologyincomputer science&Engineering
(Data Science)
Submittedby
D. Adhinadh-247R1A6716
Under theguidanceof
Shankar sir
Content =
Steps :
Evaluate the (switch) expression.
Compare it with each (case) label.
Execute the matching (case) block.
Exit the switch using (Break).
If no match, execute the (default) block.
Emphasize importance of (Break) to avoid fall-
through
Example Program
#include <stdio.h>
int main() {
int choice;
printf("Enter a number (1-3): ");
scanf("%d", &choice);
switch(choice) {
case 1:
printf("You chose One.\n");
break;
case 2:
printf("You chose Two.\n");
break;
case 3:
printf("You chose Three.\n");
break;
default:
printf("Invalid choice.\n");
}
return 0;
}
Output :
Input =2
Key Points
Key Points & Summary
Simplifies multi-branch decision-making.
Efficient for scenarios with known values.
Ensure to use break to prevent unintended fall-
through.