Conditional Statements-OCTAVE - Lab Class
Conditional Statements-OCTAVE - Lab Class
end
% marks the end of the if-else block,
indicating where the conditional statements
stop
3. if-elseif-else-end statement
The if-elseif-else-end statement is used to execute
different blocks of code based on multiple conditions.
Syntax:
if (condition1)
% Code to execute if condition1 is true
elseif (condition2)
% Code to execute if condition2 is true
else
% Code to execute if neither condition1
nor condition2 is true
end
3. if-elseif-else-end statement
Example1: Check if 0 is positive, negative or neither
Logical OR (||):
If either one of the conditions is true, the
if block will execute.
Example:
x = -3;
y = 5;
if (x > 0 || y > 0)
disp('At least one of x or y is
positive');
end
Logical Operators