Hitesh Sahu
Hitesh SahuHitesh Sahu
  1. Home
  2. β€Ί
  3. posts
  4. β€Ί
  5. …

  6. β€Ί
  7. 2 3 Logic Flow

Loading ⏳
Fetching content, this won’t take long…


πŸ’‘ Did you know?

πŸ¦₯ Sloths can hold their breath longer than dolphins 🐬.

πŸͺ This website uses cookies

No personal data is stored on our servers however third party tools Google Analytics cookies to measure traffic and improve your website experience. Learn more

Loading ⏳
Fetching content, this won’t take long…


πŸ’‘ Did you know?

🦈 Sharks existed before trees 🌳.
AI-Math

    AI-AgenticAI

    AI-DeepLearning

    AI-GenAI

    AI-Infrastructure

    AI-Machine-Learning

    AI-Math
    • Advance Maths for Machine Learning

    • Algebra for Notation and Geometry

    • ️Advance MultiVariant Linear Algebra

    • MATLAB Fundamentals

    • MATLAB Operators

    • MATLAB Control Flow & Logic

    • MATLAB Object-Oriented Programming (OOP)

    • MATLAB Plotting & Visualization

    • AI-Math Index


    AWS

    Azure

    Hobbies

    kubernetes

    Management

    Programming

    Terraform

    Z_Appendix

    0-root

Cover Image for MATLAB Control Flow & Logic
AI-Math

MATLAB Control Flow & Logic

Comprehensive guide to control flow in MATLAB including if-else statements, switch-case, for loops, while loops, break, continue, and structured program logic.

MATLAB
Control Flow
If Else
Switch Case
Loops
Programming Basics
← Previous

Terraform Configuration Management

Next β†’

Terraform Basics

Control Flow & Logic

If Else:

     if(condition)
          ...body
     elseif(condition)
          ...body
     else
          ...body  
     end 

While


    while (condition)
           ...body
           continue // skip this step
           break    // exit Loop
    end

Loop

  • use continue to skip step
  • use break to exit loop

    for v = start: step : end
        ...body
          continue // skip this step
          break    // exit Loop
    end

Switch Case

  • MATLAB executes only one case of any switch statement: If the first case statement is true, MATLAB does not execute the other case statements.

  • Variables defined within one case are not available for other cases.

  • case_expression must be a scalar, a character vector, or a cell array of scalars or character vectors.

  • switch_expression must be a scalar or character vector

    switch switch_expression
    
          case case_expression 
               ...body
             
          case {case_expression1, case_expression2} // Fall Through
             ...body
             
          otherwise
              warning('Unexpected plot type. No plot created.')
    end

Try Catch flow

  • You cannot use multiple catch blocks within a try block, but you can nest complete try/catch blocks.

  • MATLAB does not allow the use of a finally block within try/catch statements.

  try
  ...body
  
  catch ME
     switch ME.identifier
         case 'MATLAB:UndefinedFunction'
             warning('Function is undefined.  Assigning a value of NaN.');
             
         case 'MATLAB:scriptNotAFunction'
             warning(['Attempting to execute script as function. '...
                 'Running script and assigning output a value of 0.']);
  
         otherwise
             rethrow(ME)
     end
  end    
Hitesh Sahu
Written by Hitesh Sahu, a passionate developer and blogger.

Wed Feb 25 2026

Share This on

← Previous

Terraform Configuration Management

Next β†’

Terraform Basics

AI-Math/2-3-Logic-Flow
Let's work together
+49 176-2019-2523
hiteshkrsahu@gmail.com
WhatsApp
Skype
Munich πŸ₯¨, Germany πŸ‡©πŸ‡ͺ, EU
Playstore
Hitesh Sahu's apps on Google Play Store
Need Help?
Let's Connect
Navigation
Β  Home/About
Β  Skills
Β  Work/Projects
Β  Lab/Experiments
Β  Contribution
Β  Awards
Β  Art/Sketches
Β  Thoughts
Β  Contact
Links
Β  Sitemap
Β  Legal Notice
Β  Privacy Policy

Made with

NextJS logo

NextJS by

hitesh Sahu

| Β© 2026 All rights reserved.