Skip to content

Can some body help me creating a translator which translates for loop to while

ihtesham qazi

Asked Oct 6, 2005, 3:25 AM EDT1 answer
Share
LinkedInX
I want to write a sort of translator which can translate the code of for loop to coresponding while.

for example if i have :

for(int i  = 0 ; i  < 10 ;i++)
  Console.WriteLine("Hello");

it should translate like :

int i = 0;
while( i < 10)
{
   Console.WriteLine("Hello");
   i++;
}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    you could use an regular expression

    change
    for\({.+}\;{.+}\;{.+}\)\n*\{{(\n.*)*}\}

    into
    \1;\nwhile(\2)\{\4\3;\n\}

    0