If Else Switch
If Else Switch
Syntax:
if condition
% Statements
elseif another_condition
% Statements
else
% Statements
end
Example:
x = 10;
if x > 5
else
end
Switch-Case Statements:
The 'switch-case' statement is used to choose one block of code based on a variable's value.
Syntax:
switch variable
case value1
% Statements
case value2
% Statements
otherwise
% Statements
end
Example:
fruit = 'apple';
switch fruit
case 'apple'
case 'banana'
otherwise
disp('Unknown fruit.');
end