Python Forum
Function producing no result
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function producing no result
#1
def Tester():
	condition = 10
	while condition !=0:
		continue
	condition = condition -1
	if condition == 0:
		print ("You got it right")
	else: 
		print("you got it wrong")

Tester()
When i execute this, why does the result come blank?
Reply
#2
You put continue, which is not needed at all. Not to mention that the code you want to loop is not even in the loop. Get rid of the continue statement and indent the code you want under the while loop.
Reply
#3
Your code won't work because of the "continue". Continue is not needed for a while loop unless you want to skip parts of the while loop when a condition within the loop itself is met.

What you must do: Remove continue, and add an indent to all those statements within the while loop (i.e everything below while loop).

What is actually happening: The 'to be looped' is not even being considered within the loop. And even if it were, continue would make it so that they were never executed.

Continue makes it so that the other parts of the loop iteration are not executed.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  function giving different result with @functool.cache naughtysensei 3 1,838 Nov-25-2020, 03:12 PM
Last Post: naughtysensei

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020