foreach in python code example

Example 1: index in foreach c#

foreach (var item in Model.Select((value, i) => new { i, value }))
{
    var value = item.value;
    var index = item.i;
}

//or 

foreach ((MyType val, Int32 i) in Model.Select((value, i) => ( value, i )))
{
    Console.WriteLine("I am at index" + i + " and I can find the value on val");
}

Example 2: python foresch

for pet in pets:
    print pet

Example 3: py foreach

// PHP:
foreach ($array as $val) {
    print($val);
}

// C#
foreach (String val in array) {
    console.writeline(val);
}

// Python
for val in array:
    print(val)

Example 4: py foreach

names = ['tom', 'john', 'simon']

namesCapitalized = [capitalize(n) for n in names]

Example 5: foreach loop in python

# Python doesn't have a foreach statement per se. 
# It has for loops built into the language. 
# As a side note the for element in iterable syntax comes from 
# the ABC programming language, one of Python's influences

Example 6: math.pow in C# using loop

static void Main(string[] args)
        {
            float x = float.Parse(Console.ReadLine());
            int y = int.Parse(Console.ReadLine());

            float result = CalculatePower(x, y);
            Console.WriteLine("{0} to the power of{1} is {2} ", x, y, result);

        }