Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
one time loop
#7
(Jul-26-2018, 01:29 AM)DeaD_EyE Wrote: If I understood it right, you want to have some branches inside a loop, which decides to break out of this loop. Yes, this is possible and often used. In my example this is used.
yes, with all of them branching to the same place which means i only need one such loop.

(Jul-26-2018, 01:29 AM)DeaD_EyE Wrote: Each block in Python has it's own scope (maybe there are corner cases).
When you use a continue/break statement in nested scopes (eg. nested loops and other scopes),
it bubbles up, until it reaches the loop.
i won't be using continue. the only nesting i'll need is one layer of if in one layer of loop. there will be many of those if blocks, but they will not be nested in each other.

i'm skipping quoting a lot of your code because i am not using nested loops for this and so do not feel that code applies to what i am doing.

one loop, one time through, at most. perhaps one of the many breaks will cut it short.

(Jul-26-2018, 01:29 AM)DeaD_EyE Wrote: I guess with more effort you can avoid deep nested loops with if-branches.

i will avoid nested loops by having only one.

(Jul-26-2018, 01:29 AM)DeaD_EyE Wrote: Using goto in other languages, leads to unreadable code and often in unpredictable code.
In High-Level languages you'll not see any use of goto.
not always. there are cases where a carefully placed goto can make better code. what i am doing today might be if i were doing it in C. but i could also do it with break statements all wrapped in one single big do { } while(0); loop.

in Python, i'm more limited. there is no goto and no equivalent to do { } while(0); that i am aware of. so i expect to do something like:
    for once in (1):
        if condition-0:
            ...# code for condition-0:
            break
        ...# some intervening code #0
        if condition-1:
            ...# code for condition-1:
            break
        if condition-2:
            ...# code for condition-2:
            break
        if condition-3:
            ...# code for condition-3:
            break
        ...# some intervening code #1
        if condition-4:
            ...# code for condition-4:
            break
        if condition-5:
            ...# code for condition-5:
            break
        if condition-6:
            ...# code for condition-6:
            break
        ...# some intervening code #2
        if condition-7:
            ...# code for condition-7:
            break
        if condition-8:
            ...# code for condition-8:
            break
        if condition-9:
            ...# code for condition-9:
            break
        ...# some intervening code #3
        if condition-10:
            ...# code for condition-10:
            break
        if condition-11:
            ...# code for condition-11:
            break
        if condition-12:
            ...# code for condition-12:
            break
        ...# some intervening code #4
        if condition-13:
            ...# code for condition-13:
            break
        if condition-14:
            ...# code for condition-14:
            break
        if condition-15:
            ...# code for condition-15:
            break
        ...# some intervening code #5
        if condition-16:
            ...# code for condition-16:
            break
        if condition-17:
            ...# code for condition-17:
            break
        if condition-18:
            ...# code for condition-18:
            break
        ...# some intervening code #6
        if condition-19:
            ...# code for condition-19:
            break
        if condition-20:
            ...# code for condition-20:
            break
        if condition-21:
            ...# code for condition-21:
            break
        ...# some intervening code #7
        if condition-22:
            ...# code for condition-22:
            break
        if condition-23:
            ...# code for condition-23:
            break
        if condition-24:
            ...# code for condition-24:
            break
        ...# some intervening code #8
        if condition-25:
            ...# code for condition-25:
            break
        if condition-26:
            ...# code for condition-26:
            break
    ...# flow of control comes here after any break
the above is the way i'll be doing it. the above is fictional code of the same style. all i asked for is a better way to code that loop. the one first line is not saying what i am doing very well.

FYI the Linux kernel has thousands of gotos in it. Linus is an advocate for using gotos. and i have written code with gotos. maybe i'll have time to go dig it up.
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,991 Apr-24-2021, 07:52 AM
Last Post: spacedog
  Updating a matrix in a time interval inside a for loop vp1989 4 2,993 May-17-2020, 07:15 PM
Last Post: vp1989
  Loop independent of excecution time of a script Forelli 8 3,967 Feb-02-2020, 10:49 PM
Last Post: snippsat
  How to Display Multiple Time Tables With While Loop ZQ12 2 2,240 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,974 Oct-11-2019, 11:07 AM
Last Post: sebastien
  output list reducing each time through loop 3Pinter 6 3,636 Mar-19-2019, 01:31 PM
Last Post: perfringo
  Display 20 records at a time,data structure or loop pythonds 1 2,563 Mar-29-2018, 11:09 AM
Last Post: DeaD_EyE
  best pythonic one-time loop Skaperen 2 2,844 Feb-26-2018, 04:02 AM
Last Post: Skaperen
  For Loop, execute one time for every loop iteration dragan979 2 4,549 Feb-20-2018, 12:02 PM
Last Post: dragan979
  Code issue with time remaining loop. Python3 deboerdn2000 11 9,023 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