0% found this document useful (0 votes)
73 views

If Else Statement Matlab PDF

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

If Else Statement Matlab PDF

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MATLAB - IF...ELSE...

END STATEMENT
http://www.tutorialspoint.com/matlab/if_else_statement_matlab.htm

Copyright tutorialspoint.com

An if statement can be followed by an optional else statement, which executes when the
expression is false.

Syntax
The syntax of an if...else statement in MATLAB is
if <expression>
% statement(s) will execute if the boolean expression is true
<statement(s)>
else
<statement(s)>
% statement(s) will execute if the boolean expression is false
end

If the boolean expression evaluates to true, then the if block of code will be executed, otherwise
else block of code will be executed.

Flow Diagram

Example
Create a script file and type the following code
a = 100;
% check the boolean condition
if a < 20
% if condition is true then print the following
fprintf('a is less than 20\n' );
else
% if condition is false then print the following
fprintf('a is not less than 20\n' );
end
fprintf('value of a is : %d\n', a);

When the above code is compiled and executed, it produces the following result
a is not less than 20
value of a is : 100

You might also like