Jul-26-2018, 12:53 AM
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:
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
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.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.