Python Forum
have problem printing after ‘else’
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
have problem printing after ‘else’
#4
As bowlofred says, you need a counter or flag.
not_printed_yet = True
for i in range(100):
    if i % 2 == 0:
        # Will get here many times
        if not_printed_yet:
            # Only get here once
            print(i)
            not_printed_yet = False
Reply


Messages In This Thread
RE: have problem printing after ‘else’ - by deanhystad - Sep-01-2020, 08:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem printing last element from a list tester_V 3 2,487 Oct-30-2020, 04:54 AM
Last Post: tester_V

Forum Jump:

User Panel Messages

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