Programming and Graphics

(Kiana) #1

C C++/Matlab/Fortran 77Dictionary 331


Matlab Fortran 77 C++
for i=1:n Do i=1,n for (i=1;i<=n;i++)
a=a+3; a=a+3 {a=a+3;
b=b+4; b=b+4 b=b+4;
end End Do }

for i=1:n Do i=1,n for (i=1;i<=n;i++)
a=a+3 a=a+3; a=a+3; // only one
end End Do // statement is allowed

for i=j:s:n Do i=j,n,s for (i=j;i<=n;i=i+s)
... ... {...
end End Do }

while (iāˆ¼=0) Do while (i.ne.0) while (i!=0)
... ... {...
end End Do }

if(i==1) If(i.eq.1) then if(i==1)
... ... {...
end End If }

if(i==1) If(i.eq.1) then if(i==1)
x=3.0; x=3.0 x=3.0;
elseif(i==2) Else If(i.eq.2) then else if(i==2)
x=4.0; x=4.0 x=4.0;
else Else else
x=5.0; x = 5.0 x=5.0;
end End If

if(i==1 & j==2) If(i.eq.1.and.j.eq.2) k=3 if(i==1 && j==2) k=3;
k=3;
end

if(i==1|j==2) If(i.eq.1.or.j.eq.2) then if(i==1||j==2) k=3;
k=3; k=3
end End If

Table C.4 Matlab/Fortran 77/C++ equivalent structures. Note that
elseifis one word inMatlab.

Free download pdf