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
Syntax:
Flow Diagram of If...end Statement
Example
Output:
a = 122
227 183
134 177
28 196
207 72
85 174
74 140
187 100
3 16
13 196
167 85
total hours of job done by you in a year are: 3085
Great...you earned a bonus amount of Rs. 10000
|