The final assigment 1 in the "while" loop, but in the explanation of ne555 there isn't in this kind so I have difficulty to understand this difference |
Please, next time do not post a link to an image, but type the text: you are the one who is expected to do the hard work, if you want good answers.
- - -
Original text:
Esempio 4 - Cicli annidati:
1 2 3 4 5 6 7
|
i = 0;
while ( 1 < n ) { // n+1 test
for ( j = 0; j < n; j++ ) { // un ciclo for per ogni while
printf("CIAO!"); // una scrittura per ogni for
}
i = i + 1; // un assegnamento per ogni while
}
|
Assegnamento esterno: 1+
Test while: n+1+
Cicli while: n*(
Assegnamento iniziale for: 1+
Controlli ciclo for: n+1+
Incrementi ciclo for: n+
Scritture: n+
Assegnamento: 1
- - -
Numero totale di passi base: 2+4*n+3*n2
|
- - -
- - -
Translated by Google Translator
Example 4 - Nested cycles:
1 2 3 4 5 6 7
|
i = 0;
while (1 <n) { // n + 1 test
for (j = 0; j <n; j ++) { // one for loop for each while
printf ("HELLO!"); // one script for each for
}
i = i + 1; // an assignment for each while
}
|
External assignment: 1+
Test while: n + 1 +
While loops: n * ( <-- please notice there’s a parenthesis here
Initial assignment for: 1+
For loop controls: n + 1 +
Increments for loop: n +
Scriptures: n +
Assignment: 1 <-- a closing parenthesis is missing here
- - -
Total number of basic steps: 2 + 4 * n + 3 * n2
|
Writing the above numbers in a row (instead of a column), it becomes:
1 + n + 1 + n*(1 + n + 1 + n + n + 1)
Let’s carry out the multiplication:
1 + 1 + n + n + n2 + n + n2 + n2 + n
Let’s tidy up:
1 + 1 + n + n + n + n + n2 + n2 + n2
Let’s perform the additions:
2 + 4*n + 3*n2
That’s exactly how ne555 describes it.