Bifalgorithm post · Computer science one · Normalizing a Number

How can a for loop compute a summation in PHP?

How can a for loop compute a summation in PHP? (Computer science one · Normalizing a Number) — "Let’s revisit the example from Section 4.2.1 in which we comput…

Ideas in this flowchart

  • Generalización del cálculo de una suma mediante un bucle for
  • El ejemplo original calcula la suma de los enteros del 1 al 10
  • El código del ejemplo aparece en el Código de muestra 39.6
  • El código puede generalizarse para sumar hasta una variable n
  • El bucle for recorre los valores desde 1 hasta n
  • Inicialización: i comienza en 1
  • Condición: el bucle continúa mientras i sea menor o igual que n
  • Actualización: i aumenta en una unidad en cada iteración
  • Cuerpo del bucle: el valor de i se añade a sum
Feed/

How can a for loop compute a summation in PHP?

No cover

Channel

Computer science one

1 page

"Let’s revisit the example from Section 4.2.1 in which we computed the sum of integers 1 + 2 + · · · + 10. The code is presented in Code Sample 39.6. We could easily generalize this code. Instead of computing a sum up to a particular number, we could have written it to sum up to another variable $n, in which case the for loop would instead look like the following.\n\n1 for($i=1; $i<=$n; $i++) {\n\n2 $sum += $i;\n\n3 }"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.