[Solved] Convert a `while` loop to a `for` loop


I think it should be something like this :

for(;a<b--;){ 
for(d += a++ ; a != c ; )
{
  d += a++; 
}    
c+= a&b
}

The above logic works !

I ran both programs as below and they output the same result :

Program1:[derived from your program 1]

#include<stdio.h>
int main(){

int a=10,b=10,c=10,d=10;

while(a<b--)
{
do
{
    d+=a++;
}
while(a!=c);
c+=a&b;
}
printf("a=%d\tb=%d\tc=%d\td=%d",a,b,c,d);
}

And it outputs this :

a=10    b=9 c=10    d=10

Similarly the changed Program2 :[As requested]

#include<stdio.h>
int main(){

int a=10,b=10,c=10,d=10;

for(;a<b--;){
for(d += a++ ; a != c ; )
{
d += a++;
}
c+= a&b;
}
printf("a=%d\tb=%d\tc=%d\td=%d",a,b,c,d);
}

And it outputs the same :

a=10    b=9 c=10    d=10

6

solved Convert a `while` loop to a `for` loop