Skip to content

Latest commit

 

History

History
171 lines (154 loc) · 2.59 KB

File metadata and controls

171 lines (154 loc) · 2.59 KB

Test case: for in

JavaScript:

for (const i in collection) {
    var tmp = collection[i];
}

Python:

for i in range(len(collection)):
    tmp = collection[i]

Test case: for of

JavaScript:

for (const elem of collection) {
    var tmp = elem;
}

Python:

for elem in collection:
    tmp = elem

Test case: for loop ascending

JavaScript:

for (let index = 0; index < array.length; index++) {
    const element = array[index];
}

Python:

index = 0
while index < len(array):
    element = array[index]
    index += 1

Test case: for loop descending

JavaScript:

for (let index = array.length - 1; index >= 0; index--) {
    const element = array[index];
}

Python:

index = len(array) - 1
while index >= 0:
    element = array[index]
    index -= 1

Test case: for of loop with continue statement

JavaScript:

for (const elem of collection) {
    if (elem == 2) {
        continue
    }
    var tmp = elem;
}

Python:

for elem in collection:
    if elem == 2:
        continue
    tmp = elem

Test case: for in loop with break statement

JavaScript:

for (const i in collection) {
    let elem = collection[i];
    if (elem == 2) {
        break
    }
    var tmp = elem;
}

Python:

for i in range(len(collection)):
    elem = collection[i]
    if elem == 2:
        break
    tmp = elem

Test case: for in loop with empty return statement

JavaScript:

function hello() {
    for (const i in collection) {
        let elem = collection[i];
        if (elem == 3) {
            return
        }
        var tmp = elem;
    }
}

Python:

def hello():
    for i in range(len(collection)):
        elem = collection[i]
        if elem == 3:
            return
        tmp = elem

Test case: for in loop with null return statement

JavaScript:

function hello() {
    for (const i in collection) {
        let elem = collection[i];
        if (elem == 3) {
            return null
        }
        var tmp = elem;
    }
}

Python:

def hello():
    for i in range(len(collection)):
        elem = collection[i]
        if elem == 3:
            return None
        tmp = elem

Test case: for in loop with return statement

JavaScript:

function hello() {
    for (const i in collection) {
        let elem = collection[i];
        if (elem == 3) {
            return elem
        }
        var tmp = elem;
    }
}

Python:

def hello():
    for i in range(len(collection)):
        elem = collection[i]
        if elem == 3:
            return elem
        tmp = elem