0

can someone rewrite this as for loop? and A Do while loop also. int i = 0; int value = 0; while (i <=20){ if (i % 2 == 0 && i <= 10){ value = value + i * i; } else if (i % 2 == 0 && i > 10){ value = value - i; } else{ value = value - i; i = i + i; }

29th Sep 2016, 1:32 AM
Nhyn Ojastro
Nhyn Ojastro - avatar
3 odpowiedzi
0
int value = 0; for(int i = 0; i <= 20;) { if (i % 2 == 0 && i <= 10) { value += i * i; } else if (i % 2 == 0 && i > 10) { value = value - i; } else { value = value - i; i += i; } }
29th Sep 2016, 10:11 AM
Samuel Neo
Samuel Neo - avatar
0
But why is variable "i" not incremented? This loop performes only code of the 1st if...end do it endlessly
29th Sep 2016, 4:41 PM
Millia Rage
Millia Rage - avatar
0
can someone rewrite this as for loop? and A Do while loop also. int i = 0; int value = 0; do{ if (i % 2 == 0 && i <= 10){ value = value + i * i; } else if (i % 2 == 0 && i > 10){ value = value - i; } else{ value = value - i; i = i + i; }while (i <20)
29th Sep 2016, 6:58 PM
ghjc