R = 2;
P = 3.14;
A = P*R^2
ans =
12.560
Printing
|
---|
PRINT "Area = ";A;" m^2"
| disp(['Area = ' num2str(A) ' m^2']);
|
Conditional & Logical Operators
|
---|
= equal
<> not equal
< less than
<= less than or equal
> greater than
>= greater than or equal
AND and
OR or
NOT not
| == equal
~= not equal
< less than
<= less than or equal
> greater than
>= greater than or equal
& and
| or
~ not
|
Conditional Execution
|
---|
The code below shows a simple set of Block-If statements. In some
older versions of BASIC , there is no Block-If structure
and so it would have to be done strictly using GOTO
statements.
|
if Sel = 1 then
print "Selection is 1"
elseif Sel = 2 then
print "Option 2 Here"
else
print "None of the Above
endif
|
if Sel == 1
disp('Selection is 1');
elseif Sel == 2
disp('Option 2 Here');
else
disp('None of the Above');
end
* * * * * * * BASIC * * * * * * *
| * * * * * * * MATLAB * * * * * * *
|
---|
|