Nested Switch in MATLAB Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Switch statements in MATLAB allow having multiple cases as conditionals. It is an implementation of the simple if-elif-else-end cycle but, better. In this article, we will see how nested switch statements work in MATLAB with the help of example. Syntax:switch choice_1 case <1> switch choice_2 case <B> statements . end %end of inner switch . end %end of outer switch Now we see the below example printing the switch whether it is inner or outer. Example 1: Matlab % MATLAB Code for switch choice1 = input("Enter choice between 1 and 3"); choice2 = input("Enter second choice between 1 and 2"); switch choice1 case 1 fprintf("first and second choices are in outer loop") case 2 switch choice2 case 1 fprintf("Second choice is in inner loop") case 2 fprintf("Inner choice is in inner loop") end case 3 fprintf("This choice is in outer loop") end Output: Now we will use the nested switch for the situation where if the input number is 0, it prints "It is zero!" else if it is not 0, it will ask for new choice whether you want to print the number or its square root. Example 2: Matlab % MATLAB Code for Nested Switch case choice1 = input("Enter choice between 0 or any other number for next menu"); switch choice1 case 0 fprintf("It is a zero!") otherwise choice2 = input("Enter -1 for same and 1 for square root"); switch choice2 case -1 disp(choice1) case 1 disp(sqrt(choice1)) end end Output: Create Quiz Comment O owl0223 Follow 0 Improve O owl0223 Follow 0 Improve Article Tags : Software Engineering MATLAB-programs Explore Software Engineering BasicsIntroduction to Software Engineering7 min readSoftware Development Life Cycle (SDLC)6 min readSoftware Quality - Software Engineering5 min readISO/IEC 9126 in Software Engineering4 min readBoehm's Software Quality Model4 min readSoftware Crisis - Software Engineering3 min readSoftware Measurement & MetricesSoftware Measurement and Metrics4 min readPeople Metrics and Process Metrics in Software Engineering7 min readHalsteadâs Software Metrics - Software Engineering10 min readCyclomatic Complexity6 min readFunctional Point (FP) Analysis - Software Engineering8 min readLines of Code (LOC) in Software Engineering4 min readSoftware Development Models & Agile MethodsWaterfall Model - Software Engineering12 min readWhat is Spiral Model in Software Engineering?9 min readPrototyping Model - Software Engineering7 min readIncremental Process Model - Software Engineering6 min readRapid Application Development Model (RAD) - Software Engineering9 min readCoupling and Cohesion - Software Engineering10 min readAgile Software Development - Software Engineering15+ min readSRS & SPMSoftware Requirement Specification (SRS) Format5 min readSoftware Engineering | Quality Characteristics of a good SRS7 min readSoftware Project Management (SPM) - Software Engineering8 min readCOCOMO Model - Software Engineering15+ min readCapability Maturity Model (CMM) - Software Engineering10 min readIntegrating Risk Management in SDLC | Set 18 min readSoftware Maintenance - Software Engineering13 min readTesting & DebuggingWhat is Software Testing?11 min readTypes of Software Testing15+ min readTesting Guidelines - Software Engineering3 min readWhat is Debugging in Software Engineering?11 min readVerification & ValidationVerification and Validation in Software Engineering6 min readRole of Verification and Validation (V&V) in SDLC5 min readRequirements Validation Techniques - Software Engineering8 min readPractice QuestionsTop 50+ Software Engineering Interview Questions and Answers15+ min read Like