Javascript

function even_nums_to(n) {
    let ctr = 0;

    while (ctr < n) {
        ctr += 2;
        console.log(ctr);
    }
}

even_nums_to(20)
#-> 2 4 6 8 10 12 14 16 18 20

Variation: Recursion

function even_nums_to(n, ctr=2) {
    console.log(ctr);

    return ctr === n ? n : even_nums_to(n, ctr + 2);
}

even_nums_to(20);
#-> 2 4 6 8 10 12 14 16 18 20

Python

def even_nums_to(n):
    ctr = 0

    while ctr < n:
        ctr += 2
        print(ctr, end=" ")

even_nums_to(20)
#-> 2 4 6 8 10 12 14 16 18 20

Variation: Using recursion

def even_nums_to(n, ctr=2):
    print(ctr, end=" ")

    if ctr == n:
        return n
        
    return even_nums_to(n, ctr + 2)

assert even_nums_to(20) == 20
#-> 2 4 6 8 10 12 14 16 18 20

Pythonic variation: Using recursion

# 2021-07-20

def even_nums_to(n, ctr=2):
    print(ctr, end=" ")
    return n if ctr == n else even_nums_to(n, ctr + 2)

assert even_nums_to(20) == 20
#-> 2 4 6 8 10 12 14 16 18 20