Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
one time loop
#5
but the break statements are needed, or something like it (but Python does not have a goto and i would not use it for this if it did). if i don't have a break how do all those if clauses (that are not all connected together, hence making elif not usable) join together at the end?

in C i had a macro named once defined to clearly make a one-time loop. but most people doing C or like code did:
    do {
        ...
    } while(0);
and GCC optimized it and understood the intention of all this. a few programmers just used a goto statement to join all the clauses at the end of them (and, thus, did not use break).

i need to create a wrapper around a big block of code that has several smaller blocks of code. each of these smaller blocks of code tests a condition and if the condition is met may execute some code, then needs to proceed to outside the big block of code. all these conditions of flow of control then join up at the end. if only these smaller blocks existed and nothing else, then this could be done by using elif for each smaller block (plain if for the first). the end of all these elifs (maybe also with an else at the end) would be where the flow of control all joins up. another way to do this is with deeply nested if/else. but the depth of this nesting can get quite extreme and make the code hard to read. the 3rd way to do this is to have a sequence of plain if statements with an escape method like a goto or if surrounded by a loop, and a break statement instead of a goto.

genuine examples would have to be very large to avoid someone suggesting the (ugly) deeply nested if/else. this is one reason why i am not ready to post a use-case.

i already explained that i can (and will) code this in Python as a one-time loop and will use for once in (1): if no better code is shown to me. but if you guys have never seen this kind of problem, i wonder if you have ever dealt with largely complex logic. i am wondering if maybe Python might have a nice clean way to do this.
Tradition is peer pressure from dead people

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


Messages In This Thread
one time loop - by Skaperen - Jul-25-2018, 03:39 PM
RE: one time loop - by Larz60+ - Jul-25-2018, 05:18 PM
RE: one time loop - by Skaperen - Jul-25-2018, 09:14 PM
RE: one time loop - by DeaD_EyE - Jul-26-2018, 01:29 AM
RE: one time loop - by Skaperen - Jul-26-2018, 03:45 AM
RE: one time loop - by Larz60+ - Jul-25-2018, 09:24 PM
RE: one time loop - by Skaperen - Jul-26-2018, 12:53 AM
RE: one time loop - by stranac - Jul-26-2018, 07:09 AM
RE: one time loop - by Skaperen - Jul-26-2018, 02:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to measure execution time of a multithread loop spacedog 2 2,927 Apr-24-2021, 07:52 AM
Last Post: spacedog
  Updating a matrix in a time interval inside a for loop vp1989 4 2,945 May-17-2020, 07:15 PM
Last Post: vp1989
  Loop independent of excecution time of a script Forelli 8 3,887 Feb-02-2020, 10:49 PM
Last Post: snippsat
  How to Display Multiple Time Tables With While Loop ZQ12 2 2,206 Nov-10-2019, 04:15 AM
Last Post: ZQ12
  Time execution of a "for loop" with zip different in 2 equivalent context sebastien 1 1,952 Oct-11-2019, 11:07 AM
Last Post: sebastien
  output list reducing each time through loop 3Pinter 6 3,584 Mar-19-2019, 01:31 PM
Last Post: perfringo
  Display 20 records at a time,data structure or loop pythonds 1 2,500 Mar-29-2018, 11:09 AM
Last Post: DeaD_EyE
  best pythonic one-time loop Skaperen 2 2,807 Feb-26-2018, 04:02 AM
Last Post: Skaperen
  For Loop, execute one time for every loop iteration dragan979 2 4,478 Feb-20-2018, 12:02 PM
Last Post: dragan979
  Code issue with time remaining loop. Python3 deboerdn2000 11 8,915 May-04-2017, 04:53 PM
Last Post: deboerdn2000

Forum Jump:

User Panel Messages

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