how to build a loop that write previous number's 1.8 times
for example
`for ($i = 1; $i <= 11; $i ) {echo $i;}`
$i should give me an output like : 1, 1.8, 3.24, 5.8 , 10.5 so it should give me previous number's 1.8 times
CodePudding user response:
In Java it's simple as:
for (double i = 1; i <= 11; i *= 1.8) {
System.out.println(i);
}
I guess you can convert it to the language you use.
CodePudding user response:
$i means that you are incrementing the value of $i variable by 1 unit (the initial value you assigned to 1. Each following iteration it will be increased by 1 until it reaches 11 (including 11)). If I understood correctly the question, you want to have a step of 1.8
for ($i = 1; $i <= 11; $i= $i * 1.8) {
echo $i;
}
Or another alternative would be:
$result = 1;
for ($i = 1; $i <= 11; $i ) {
$result *= 1.8;
echo $result;
}
