### Thread: Loop an If condition until .. ?

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Oct 2012
Posts
3
Rep Power
0

#### Loop an If condition until .. ?

Is it possible to have a code that would do my math until the results are between 50 and 200 ?
My equation can go very high and I have to work with either /2 or *2 until I get between those 2 targets. As high as 11 times doing /2 (hence the 11 if)

Could you help me please ? :)

Code:
```  switch (choix)
{
case 1:
printf("f: ");
scanf("%lf", &B);
C = A/(1/B);
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
if(C<50) C=2*C;
if(C>200) C=C/2;
printf("t = %.10f \n\n",C);
break;```
2. Like
Code:
```while ( C<50 || C>200 ) {
if(C<50) C=2*C;
if(C>200) C=C/2;
}```
Or even
Code:
```while ( C < 50 ) C = C * 2;
while ( C > 200 ) C = C / 2;```