MATLAB if...end statement
- The if is a conditional statement that provides the functionality to choose a block of code to execute at run time.
- A predefined condition is checked, and the remaining code executes based on the output of the condition.
- The if statement is defined by the if
- The control flows within the if block if the condition is found true.
- Always close the if block with the end
- The elseif and else are optional, use them if there are more conditions to be checked.
- The elseif and else are an optional parts of the if statement and don't require additional end
- Remember not to use space in between else & if of the elseif keyword, because this leads to nested if statement and each if block needs to be close with the end
- There is no limit to use multiple elseif
- We can nest the if statement by using it within another if
Flow Diagram of If...end Statement
a = 12×2
total hours of job done by you in a year are: 3085
Great...you earned a bonus amount of Rs. 10000