-2
# pede pelo nome do aluno, ou termina o programa, se "fim".
while(True):
    aluno = input("\nInsira o nome do aluno: ")
    while(aluno == "" or aluno == None):
        aluno = input("Por favor insira o nome do aluno: ")
    if (aluno == "Fim" or aluno == "fim"):
        print(bold + "Fechando o programa...\n" + bold_end) 
        sys.exit()  
    if (aluno.istitle() != True):
        qst = input("\nEste não parece ser um nome regular. Tem certeza que deseja prosseguir?")
        if (qst == 'N' or qst == 'No' or qst== 'Não' or qst == "n" ):
            continue

This is a little snippet of a program I've made to help me correcting the tests of my students. He does exactly what I want, but the last four lines that I've exposed work, and I don't know why.

If a name that is not composed not only of uppercase and lowercase letters is inserted, the program must question if I want to proceed with that name. If I type "N" or anything of the like, the program restarts, and asks me again for the name of the student. If I type in any other thing, the program proceeds as it should. The question is: why?

Paulo Soares
  • 177
  • 3
  • 18
  • 2
    do you have anything inside `while(True)` below `continue` ? – furas Feb 03 '17 at 02:32
  • @furas yes I do. The code keeps on asking the user for the number of correct answers. What I wanted is for, after negating, the code would go back to the start of the while loop, and if I said yes, that It would keep on going. It does exactly that, but I've kinda done it by accident. – Paulo Soares Feb 03 '17 at 02:35
  • Don't use ` != True`. Use `not ` instead. – Martijn Pieters Feb 03 '17 at 02:35
  • 1
    if you answert `N` then `continue` returns to `while(True)` - if you answer something different then it doesn't execute `continue` and it executes next lines of code which are inside `while(True)` – furas Feb 03 '17 at 02:39

1 Answers1

1

You seem to have mixed up continue and break.

break ends a loop. continue starts the next iteration (continues the loop from the top).

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343