mardi 6 avril 2021

Different Output in While Loop in Django Python

I have a while loop function. But they give code 1 and code 2 different outputs. Why is this so?

len(yourSkills) = 7

Code 1

def getSkills():
    i = 0
    while i < len(yourSkills):
        skill = "<li>" + yourSkills[i] + "<span class='percent'>" + skillsPercent[i]  + "</span></li>"
        i += 1
        if i == len(yourSkills):
            return html.unescape(skill)

Code 2

def getSkills():
    i = 0
    while i < len(yourSkills):
        skill = "<li>" + yourSkills[i] + "<span class='percent'>" + skillsPercent[i]  + "</span></li>"
        if i == len(yourSkills):
            return html.unescape(skill)
        i += 1

Code 1 Output is = the value I want

Code 2 Output is = none

So while I get the value I want in the first code, I can't get it in the second code.

Aucun commentaire:

Enregistrer un commentaire