Concept
How can a for loop compute a generalized summation in PHP?
ComputerScienceOne / Summation
"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 }"
Related Ideas
- How can a summation loop be generalized to sum up to a variable n?ComputerScienceOne · Summation
- How do you compute a summation with a for loop in C?ComputerScienceOne · Summation
- How can a Java for loop be generalized to sum integers up to another variable?ComputerScienceOne · Normalizing a Number
- How can a for loop calculate the sum of numbers from 1 to 10?ComputerScienceOne · Nested Loops
- How are for loops structured in PHP?ComputerScienceOne · For Loops
- How does an enhanced for loop compute the sum of a list of integers?ComputerScienceOne · Summation
- How does an enhanced for loop calculate the sum of integers in a Java list?ComputerScienceOne · Normalizing a Number
- How do nested for loops execute in PHP?ComputerScienceOne · Nested Loops