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; }
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;
}
}
0
But why is variable "i" not incremented? This loop performes only code of the 1st if...end do it endlessly
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)