c - Convert a `while` loop to a `for` loop -


i'm new in c, , not sure if loop correctly converted.

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

and it's loop

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

i know it's maybe easy , stupid, hope you'll me :) thx

i think should :

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

the above logic works !

i ran both programs below , output same result :

program1:[derived program 1]

#include<stdio.h> int main(){  int a=10,b=10,c=10,d=10;  while(a<b--) { {     d+=a++; } while(a!=c); c+=a&b; } printf("a=%d\tb=%d\tc=%d\td=%d",a,b,c,d); } 

and outputs :

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

similarly changed program2 :[as requested]

#include<stdio.h> int main(){  int a=10,b=10,c=10,d=10;  for(;a<b--;){ for(d += a++ ; != c ; ) { d += a++; } c+= a&b; } printf("a=%d\tb=%d\tc=%d\td=%d",a,b,c,d); } 

and outputs same :

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

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -