Ripetizione
Precalcolata


Il ciclo con controllo in testa assume spesso una forma standardizzata
BasicPascalC
I=1
While I <= N
    Istr1
    ...
    I=I+1
Wend
I:=1;
While I <= N Do
    Begin
        Istr1;
        ...
        I:=I+1;
    End;
i=1;
while(i <= N)
{
    istr1;
    ...
    i=i+1;
}


nella quale
In questi casi tutta la scrittura è convenientemente riassunta nella struttura di controllo for()
BasicPascalC
PER I DA 1 A N ESEGUI
    INIZIO
        Istr1
        ...
    FINE
For I=1 to N
    Istr1
    ...
Next I
For I:=1 To N Do
    Begin
        Istr1;
        ...
    End;
for(i=1; i <= N; i++)
{
    istr1;
    ...
}
PER I DA N A 1 ESEGUI
    INIZIO
        Istr1
        ...
    FINE
For I=N to 1 Step -1
    Istr1
    ...
Next I
for I:=N DownTo 1 Do
    Begin
        Istr1;
        ...
    End;
for(i=N; i >= 1; i--)
{
    istr1;
    ...
}
For I=... to ... Step ...
    Istr1
    ...
Next I
for(...; ...; ...)
{
    istr1;
    ...
}


Ci sono molte differenze
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki