python - My while loop isn't working -


this part of code , not sure why while loop doesn't let user try again. please me!

answer3 = true while answer3:     if answer2.lower() == "no" or answer2.lower() == "nah":         print ("okay ... bye.")         sys.exit()     elif answer2 == "yes".lower() or answer2.lower() == "yeah" or answer2.lower() == "yes":         print ("okay ... \n")     else:         print("please enter valid answer! try again!\n")     break 

the break function exits while loop, if answer3 still has value true, stop loop after end of it's first cycle. remove break , shall work.

it terminates current loop , resumes execution @ next statement, traditional break statement in c.

the common use break when external condition triggered requiring hasty exit loop. break statement can used in both while , loops.

if using nested loops, break statement stops execution of innermost loop , start executing next line of code after block.

enter image description here


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -