Jul-26-2018, 03:45 AM
(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).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.
When you use acontinue
/break
statement in nested scopes (eg. nested loops and other scopes),
it bubbles up, until it reaches the loop.
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.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
In High-Level languages you'll not see any use of goto.
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 breakthe 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.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.