Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for/else ... for/elif?
#1
an else: can follow a loop to handle the case of no break statements being done in that loop. but if the first thing that needs to be done in that else: block is an if statement, can that be coded as an elif statement instead of an else: followed by an (indented) if?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
The answer (no) is in this part of the documentation of python's syntax.
Reply
#3
thanks. i do remember seeing some language long ago which implemented elif by rebuilding the code. i don't think it had else for loops but if it did, coding elif would have created the else block and the if block, so it would have worked there. i just didn't know if Python could have been doing the same kind of thing.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Whats the right way to refactor this Big if/elif/elif ? pitosalas 1 2,237 Jul-28-2019, 05:52 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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