tipo dichiarazione assegnazione input-output FOR WHILE REPEAT IF THEN CASE-SELECT
turbo pascal | vba-visual basic | excel |
costanti | ||
const nome=valore; | const nome as tipo=valore | |
const a=100;b='stringa';c=FALSE | const k as integer=100 | |
const p=3.14; | const p as double=3.14 | |
const k=100 | ||
const s="testo" | ||
tipo variabili | ||
integer,shortint,longint,real,byte,word | integer,single,double | ...................................... |
string,char | string | |
boolean | boolean | |
dichiarazione variabili | ||
var a,b,c:tipo; | dim x as tipo | |
var a,b:integer; | dim a,b as integer | |
var x,y:real; | dim a as integer,x as double | |
var x:array[1..n] of tipo; | dim x(n) as tipo | |
var x:array[1..5] of integer; | dim x(5) as integer | |
var x:array[1..5] of string[10]; | dim x(5) as string | |
var x:array[1..5] of char; | ||
var x:array[1..r,1..q] of tipo | ||
var x:array[1..5,1..5] of integer; | ||
assegnazione valore | ||
a:=valore; | a=valore | |
a:=15; | a=cells(riga,colonna) | |
x:="a"; | a=label.caption | |
y:="testo"; | a=textbox.text | |
x[n]:=valore; | x[n]=cells(r,c) | |
x[3]:=5; | x[3]=cells(3,2) | |
x[3]=label.caption | ||
x[3]=text.box.text | ||
x[r,c]:=valore; | ||
x[2,3]:=50; | ||
Input-Output | ||
read(x); | x=cells(riga,colonna) | |
readln(x); | x=label.caption | |
write('testo:');readln(x); | x=textbox.text | |
write(x); | cells(riga,colonna)=x | |
writeln(x); | label.caption=x | |
writeln('testo',x); | textbox.text=x | |
msgbox(x)..msgbox("testo") | ||
writeln(x[n]); | cells(r,c)=x(n) | |
writeln(x[3]); | cells(2,3)=x(2) | |
label.caption=x(3) | ||
textbox.text=x(4) | ||
writeln([r,c]); | ||
writeln([2,3]); | ||
cicli di iterazione con FOR.. | ||
for k :=n to q do | for k=n to q | |
istruzione1; | istruzione1 | |
next k | ||
for k:=n to q do | for k=n to q | |
begin | istruzione1 | |
istruzione1; | istruzione2 | |
istruzione2; | istruzione3 | |
end; | next k | |
for k:=n to q step p do | for k=n to q step p | |
istruzione1; | istruzioni | |
next k | ||
For Each c In Selection | ||
cicli di iterazione con WHILE | ||
k:=n; | k=n | |
while k<n do | do while k<n | |
begin | istruzioni | |
istruzioni; | istruzioni | |
end; | loop | |
cicli di iterazione con REPEAT..DO | ||
k:=n; | k=n | |
repeat | do | |
istruzioni; | istruzioni | |
until k>q; | loop until k>q | |
selezione con IF..THEN..ELSE | ||
if a>b then istruzione1; | if a>b then istruzione | =se(a1>b1;a1*b1;0) |
if a>b then | if a>b then | =se(a1<b1;a1+b1;0) |
begin | istruzione1 | =se(e(a1<b1;c1<d1);a1;b1) |
istruzione1; | istruzione2 | =se(o(a1<b1;c1>d1);a1;b1) |
istruzione2; | istruzione3 | |
end; | end if | |
if a>b then | if a>b then | |
istruzione1 | istruzione1 | |
else | else | |
istruzione2; | istruzione2 | |
end if | ||
selezione con CASE k OF | SELECT CASE K | |
k:=n; | k=n | |
case k of | select case k | |
1:istruzione1; | case 1 | |
2:istruzione2; | istruzioni | |
3,4,5:istruzione3; | case 2 | |
else | istruzioni | |
istruzione4; | case 3,4,5 | |
end; | istruzioni | |
end select | ||
procedure | call | |
procedure nome(p,q:tipo); | public sub nome(p as tipo,q as tipo) | |
begin | dim x,y as tipo | |
istruzione1; | istruzione1 | |
istruzione2; | istruzione2 | |
end; | end sub | |
chiamata di procedura | chiamata di call | |
nomeprocedura(a,b); | call nomeprocedura(a,b) | |
function | function | |
function nome(x:tipo;n:tipo):tipo; | public Function nome(a as tipo,b as tipo) | |
function potenza(x:real;n:integer):real; | public Function esegue(a as integer,b as integer) | |
begin | dim somma as integer | |
if n=0 then potenza:=1 | somma=a+b | |
else | esegue=somma | |
potenza:=x*potenza(x,n-1) | end function | |
end; | ||
writeln(potenza(a,b):6:2); | cells(r,c)=esegue(a,b) | |
label.caption=esegue(a,b) |