Skip to content
Advertisement

Translating a for loop from c# to python (ironpython) [closed]

I’m translating a chunk of code I have to use, from C# to Python. I’m not fluent in C#. How would you translate the code?:

Line foundLine = null;
for (int j = 0; null == foundLine && j < 2; j++)
{
do some stuff;
}

 

Advertisement

Answer

This would be the python translation for the above C# code:

foundLine = None;
j = 0
while j < 2 and foundLine is None:
    #do some stuff;
    j += 1
Advertisement