• Re: Trying to understand nested loops

    From Lars Liedtke@21:1/5 to All on Fri Aug 5 09:47:22 2022
    Hello,

    this looks to me like it might be a piece of homework, as it would be
    given by teachers or professors.

    This list has got the rule, that members do not solve other's homework. Because very often homework is meant to sit down and think about it.

    But maybe I interpreted that wrongly, so if you could try to formulate
    in words what this loop does, I or other people on this list, will be
    pleased to show you where you might have got things wrong and how it
    really works.

    Cheers

    Lars


    --
    Lars Liedtke
    Software Entwickler


    Phone:
    Fax: +49 721 98993-
    E-mail: lal@solute.de


    solute GmbH
    Zeppelinstraße 15
    76185 Karlsruhe
    Germany


    Marken der solute GmbH | brands of solute GmbH
    billiger.de | Shopping.de


    Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
    Webseite | www.solute.de
    Sitz | Registered Office: Karlsruhe
    Registergericht | Register Court: Amtsgericht Mannheim
    Registernummer | Register No.: HRB 110579
    USt-ID | VAT ID: DE234663798


    Informationen zum Datenschutz | Information about privacy policy http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

    Am 05.08.22 um 09:34 schrieb ojomooluwatolami675@gmail.com:
    Hello, I’m new to learning python and I stumbled upon a question nested loops. This is the question below. Can you please how they arrived at 9 as the answer. Thanks

    var = 0
    for i in range(3):
    for j in range(-2,-7,-2):
    var += 1
    print(var)

    Sent from my iPhone
  • From ojomooluwatolami675@gmail.com@21:1/5 to All on Fri Aug 5 08:34:45 2022
    Hello, I’m new to learning python and I stumbled upon a question nested loops. This is the question below. Can you please how they arrived at 9 as the answer. Thanks

    var = 0
    for i in range(3):
    for j in range(-2,-7,-2):
    var += 1
    print(var)

    Sent from my iPhone

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Frank Millman@21:1/5 to ojomooluwatolami675@gmail.com on Fri Aug 5 09:56:03 2022
    On 2022-08-05 9:34 AM, ojomooluwatolami675@gmail.com wrote:
    Hello, I’m new to learning python and I stumbled upon a question nested loops. This is the question below. Can you please how they arrived at 9 as the answer. Thanks

    var = 0
    for i in range(3):
    for j in range(-2,-7,-2):
    var += 1
    print(var)


    Welcome to Python. I am sure you are going to enjoy it.

    To learn Python, you must learn to use the Python interactive prompt
    (also known as the REPL).

    Type 'python' at your console, and it should bring up something like this -

    C:\Users\E7280>python
    Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64
    bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.


    The confusing part of your example above is 'for j in range(-2,-7,-2)'.

    To find out what it does, enter it at the '>>>' prompt -

    for j in range(-2, -7, -2):
    ... print(j)
    ...
    -2
    -4
    -6


    For the purposes of your exercise, all you need to know at this stage is
    that it loops three times.

    Does that help answer your question? If not, feel free to come back with
    more questions.

    BTW, there is an indentation error in your original post - line 5 should
    line up with line 4. It is preferable to copy/paste your code into any
    messages posted here rather than type it in, as that avoids the
    possibility of any typos.

    Frank Millman

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to Lars Liedtke on Fri Aug 5 18:30:05 2022
    On 05Aug2022 09:47, Lars Liedtke <lal@solute.de> wrote:
    this looks to me like it might be a piece of homework, as it would be
    given by teachers or professors.

    This list has got the rule, that members do not solve other's
    homework. Because very often homework is meant to sit down and think
    about it.

    Very true.

    However, we're happy to help people understand things.

    In this case it look like Frank has provided apt advice, showing the OP
    how to see how many times the inner loop runs, which affects how many
    times `var+=1` occurs.

    Cheers,
    Cameron Simpson <cs@cskk.id.au>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From GB@21:1/5 to Frank Millman on Fri Aug 5 10:56:34 2022
    On 05/08/2022 08:56, Frank Millman wrote:

    BTW, there is an indentation error in your original post - line 5 should
    line up with line 4.

    As a Python beginner, I find that Python is annoyingly picky about
    indents. And, the significance of indents is a bit of a minefield for beginners.

    For example, in the above code, the indent of the final line very
    significantly affects the results:

    print(var)
    print(var)
    print(var)

    These are all different.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Weatherby,Gerard@21:1/5 to All on Fri Aug 5 13:13:09 2022
    SXTigJlzIGFsc28gYSBwb29yIGNvZGUgZXhhbXBsZS4gRG9pbmcgYSBwb2ludGxlc3MgZG91Ymxl IGxvb3AgaXMgbm90IGdvb2QgaW5zdHJ1Y3Rpb25hbCBwcmFjdGljZSwgZXNwZWNpYWxseSB3aGVu IHNpbXBsZXIgYWx0ZXJuYXRpdmVzIGV4aXN0LiBlLmcuDQoNCmZvciBpIGluIHJhbmdlKDMpOg0K ICAgIGZvciBqIGluIHJhbmdlKC0yLi03LC0yKToNCnByaW50KGkgK2ogKQ0KDQoNCuKAlA0KR2Vy YXJkIFdlYXRoZXJieSB8IEFwcGxpY2F0aW9uIEFyY2hpdGVjdCBOTVJib3ggfCBOQU4gfCBEZXBh cnRtZW50IG9mIE1vbGVjdWxhciBCaW9sb2d5IGFuZCBCaW9waHlzaWNzDQogVUNvbm4gSGVhbHRo IDI2MyBGYXJtaW5ndG9uIEF2ZW51ZSwgRmFybWluZ3RvbiwgQ1QgMDYwMzAtNjQwNiB1Y2hjLmVk dQ0KT24gQXVnIDUsIDIwMjIsIDQ6MzggQU0gLTA0MDAsIG9qb21vb2x1d2F0b2xhbWk2NzVAZ21h aWwuY29tIDxvam9tb29sdXdhdG9sYW1pNjc1QGdtYWlsLmNvbT4sIHdyb3RlOg0KDQp2YXIgPSAw DQpmb3IgaSBpbiByYW5nZSgzKToNCmZvciBqIGluIHJhbmdlKC0yLC03LC0yKToNCnZhciArPSAx DQpwcmludCh2YXIpDQo=

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dieter Maurer@21:1/5 to ojomooluwatolami675@gmail.com on Fri Aug 5 19:38:05 2022
    ojomooluwatolami675@gmail.com wrote at 2022-8-5 08:34 +0100:
    Hello, I’m new to learning python and I stumbled upon a question nested loops.

    For future, more complex, questions of this kind,
    you might have a look at the module `pdb` in Python's runtime library.
    It implements a debugger which allows you (among other features)
    to interactively run a program line by line
    and explore the state of all involved variables.
    There are also IDEs (= Integrated Development Environments) which
    support this.

    Whenever a program does things you do not understand,
    debugging usually helps to bring light into the scene.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Grant Edwards@21:1/5 to NOTsomeone@microsoft.invalid on Fri Aug 5 12:53:59 2022
    On 2022-08-05, GB <NOTsomeone@microsoft.invalid> wrote:

    BTW, there is an indentation error in your original post - line 5
    should line up with line 4.

    As a Python beginner, I find that Python is annoyingly picky about
    indents. And, the significance of indents is a bit of a minefield for beginners.

    As a C beginner, you'll find that C is annoyingly picky about curly
    braces and semcolons.

    All programming languages are picky about syntax.

    For example, in the above code, the indent of the final line very significantly affects the results:

    print(var)
    print(var)
    print(var)

    These are all different.

    Indeed. It looks different, and it _is_ different. Seems like a good
    thing to me. I like programs to do what it looks like they are going
    to do.

    In C, this doesn't do what it looks like it's supposed to do.

    if (foo)
    do_this();
    and_this();
    then_do_this();

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mats Wichmann@21:1/5 to All on Fri Aug 5 14:57:41 2022
    On 8/5/22 03:56, GB wrote:
    On 05/08/2022 08:56, Frank Millman wrote:

    BTW, there is an indentation error in your original post - line 5
    should line up with line 4.

    As a Python beginner, I find that Python is annoyingly picky about
    indents.  And, the significance of indents is a bit of a minefield for beginners.

    For example, in the above code, the indent of the final line very significantly affects the results:

    print(var)
        print(var)
            print(var)

    These are all different.

    Yes, very picky. Python has chosen to use a (consistent) indent to
    indicate a code block, as opposed to using extra syntactical characters
    (curly braces, etc.) to delimit blocks. It's just a choice that was
    made about how to instruct the interpreter what you mean, and there's
    some argument that it improves readability later, when you go look at
    your code months later, or someone else's code: the requirement to have consistent indents means your brain can trust that the way the code is
    indented is meaningful, rather than arbitrary. Also note that most
    (all?) code formatters for other languages will enforce consistent
    indenting too, In Python it just happens to be part of the language
    rather than optional. So: you need to be clear about what you mean by
    indenting correctly. All good code editors that understand Python
    understand about this and will help you as much as they can.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Stromberg@21:1/5 to ojomooluwatolami675@gmail.com on Fri Aug 5 15:50:49 2022
    On Fri, Aug 5, 2022 at 12:35 AM <ojomooluwatolami675@gmail.com> wrote:

    Hello, I’m new to learning python and I stumbled upon a question nested loops. This is the question below. Can you please how they arrived at 9 as the answer. Thanks

    var = 0
    for i in range(3):
    for j in range(-2,-7,-2):
    var += 1
    print(var)


    A debugger is useful for more than debugging; it can also help give an intuition for control flow. If you single step through this snippet with a debugger, you'll probably see what's happening.

    Of if you don't have (or want) a debugger, you could change it to:

    var = 0
    for i in range(3):
    print('i is', i)
    for j in range(-2,-7,-2):
    print('j is', j)
    var += 1
    print(var)

    And note that 3 times 3 is 9.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dn@21:1/5 to avi.e.gross@gmail.com on Sat Aug 6 11:57:30 2022
    On 06/08/2022 11.41, avi.e.gross@gmail.com wrote:
    I wonder if someone is pulling our leg as they are sending from an invalid email address of "GB <NOTsomeone@microsoft.invalid>" which is a bit sick.

    There are a number of folk who use evidently false email addresses - the
    OP's had me amused.

    Such 'hiding' is a matter for the List-Admins (thanks for all the work
    exerted on our behalf!) and how it fits with the Code-of-Conduct.


    I have trouble imagining ANYONE learning a language like python without rapidly being told that python uses indentation instead of various ways to detect when a body of text is considered a single composite item.

    And code like their example is also nonsense:

    print(var)
    print(var)
    print(var)

    Another way to look at that post, and what the author may have meant; is
    that the final print(), incorrectly indented in the OP, could have been
    written with three different indentations, and thus have three very
    different effects (cf that they are all to be used, as-is).
    --
    Regards,
    =dn

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Stromberg@21:1/5 to NOTsomeone@microsoft.invalid on Fri Aug 5 16:55:18 2022
    On Fri, Aug 5, 2022 at 12:30 PM GB <NOTsomeone@microsoft.invalid> wrote:

    On 05/08/2022 08:56, Frank Millman wrote:

    BTW, there is an indentation error in your original post - line 5 should line up with line 4.

    As a Python beginner, I find that Python is annoyingly picky about
    indents. And, the significance of indents is a bit of a minefield for beginners.

    No, you should indent properly anyway. Python just reduces the number of
    things to worry about.

    Please see: https://stromberg.dnsalias.org/~strombrg/significant-whitespace.html
    ...for the usual.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dn@21:1/5 to Dan Stromberg on Sat Aug 6 11:15:26 2022
    On 06/08/2022 10.50, Dan Stromberg wrote:
    On Fri, Aug 5, 2022 at 12:35 AM <ojomooluwatolami675@gmail.com> wrote:
    ...

    Of if you don't have (or want) a debugger, you could change it to:

    var = 0
    for i in range(3):
    print('i is', i)
    for j in range(-2,-7,-2):
    print('j is', j)
    var += 1
    print(var)

    And note that 3 times 3 is 9.

    Combining the above advice and illustration, with several more recent
    comments about indentation revealing structure, should the above be
    amended to:

    indent = " " # your choice of how many spaces/tabs
    ...
    print( "i is", i )
    ...
    print( indent + "j is", j )
    ...
    print( indent + indent, var ) # add sep="" if pernickety
    ...

    Thus, the output matches the code and each complements the other's view
    of structure!

    --
    Regards,
    =dn

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to Frank Millman on Fri Aug 5 19:41:59 2022
    I wonder if someone is pulling our leg as they are sending from an invalid email address of "GB <NOTsomeone@microsoft.invalid>" which is a bit sick.

    I have trouble imagining ANYONE learning a language like python without
    rapidly being told that python uses indentation instead of various ways to detect when a body of text is considered a single composite item.

    And code like their example is also nonsense:

    print(var)
    print(var)
    print(var)

    On my version of python, and likely most or all, it generates an error
    message like:

    SyntaxError: multiple statements found while compiling a single statement

    The way I see it, it is beyond irrelevant when learning a language what YOU (the learner) think. The rules are the rules. If you do not like them and do not have to use that language, go find another you might like.

    If you want to stay with the language, you not only adjust but welcome new
    ways of doing things. I have seen people stuck on code like this:

    a, b, c = 5,4,3

    others get nauseous at something like:

    a, b, _ = some_func(args)

    But the whole point is learning to appreciate what someone decided might
    make the language more useful, easier to program in, avoid errors, be more flexible, or maybe more efficient, or whatever design criteria apply. Only
    once you understand more things like that, can you be in a position to
    critique it as horrible.

    So, speaking for myself, the poster is assumed, for now, to not be worth responding to. I doubt they are a true beginner or at least that they have spent any serious time learning.


    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of GB
    Sent: Friday, August 5, 2022 5:57 AM
    To: python-list@python.org
    Subject: Re: Trying to understand nested loops

    On 05/08/2022 08:56, Frank Millman wrote:

    BTW, there is an indentation error in your original post - line 5
    should line up with line 4.

    As a Python beginner, I find that Python is annoyingly picky about indents. And, the significance of indents is a bit of a minefield for beginners.

    For example, in the above code, the indent of the final line very
    significantly affects the results:

    print(var)
    print(var)
    print(var)

    These are all different.



    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to avi.e.gross@gmail.com on Fri Aug 5 20:28:31 2022
    I had considered that, Dave. Albeit others did at least put in some
    three-dot markers to show there was other code between the three lines
    shown.

    But the same silly argument they used applies elsewhere. Consider nested
    calls like:

    Delta(Gamma(Beta(Alpha)))

    Now say one of those functions takes an argument like 666.

    The following lines all mean different things, especially if all the above functions can take an optional argument of 666.

    Delta(Gamma(Beta(Alpha,666)))
    Delta(Gamma(Beta(Alpha),666))
    Delta(Gamma(Beta(Alpha)),666)
    Delta(666,Gamma(Beta(Alpha)))
    Delta(Gamma(666,Beta(Alpha)))
    Delta(Gamma(Beta(666,Alpha)))

    And of course any such function calls may be in contexts such as this:

    Result, const = Delta(Gamma(Beta(Alpha))),666

    My point is that whether using indentation or parentheses or braces or other grouping techniques, exact placement according to the rules must apply. I
    often write code where I use indentation to remind ME which argument goes
    with which, such as this (more often not in python where indentation has no real meaning and things can span multiple lines.

    This:

    Delta(Gamma(666,Beta(Alpha)))

    May make more sense to write like this:

    Delta(Gamma(666,
    Beta(Alpha)))

    Or in a more general case where each of the functions may take multiple arguments before and/or after nested, calls, I might have a long convoluted code where all arguments to a particular function are vertically aligned and
    it is easier to spot if you left one out or put it in the wrong place.

    It becomes a somewhat childish argument when writing CODE in any language
    with rules, to suggest that it should ignore your mistakes and assume you
    meant to have a comma here or parentheses there and similarly, that the indentation level should govern which block your print statement is part of.


    Hence my suggestion that perhaps someone is in a sense punking us

    Of course it is perfectly possible the software this person is using makes
    that deliberately unworkable email address as I have seen this elsewhere. It just raises my suspicion level when I have seen other posts on various
    mailing lists ranging from someone with pretty much no knowledge about a
    topic but wanting someone to do their homework, to someone who throws in something (perhaps incendiary) to watch others waste their time trying to
    deal with their best guesses of what was wanted, to one guy who seems to
    write articles or books and wants to see what people think but then does not participate or tell us that is what they wanted.

    My point was not to tell anyone else here what to do, simply that I will be cautious with such posters as I have way better things to do!

    Nested loops are indeed a hard topic for many. But when explained it no
    longer seems reasonable to ask why print statements at different levels of nesting differ.

    Not to me, at least.

    - Avi (for those like someone on another language/group who did not know how
    to address me in overall too-polite format and referred to me as "Dear
    " followed by more lines.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of dn
    Sent: Friday, August 5, 2022 7:58 PM
    To: python-list@python.org
    Subject: Re: Trying to understand nested loops

    On 06/08/2022 11.41, avi.e.gross@gmail.com wrote:
    I wonder if someone is pulling our leg as they are sending from an
    invalid email address of "GB <NOTsomeone@microsoft.invalid>" which is a
    bit sick.

    There are a number of folk who use evidently false email addresses - the
    OP's had me amused.

    Such 'hiding' is a matter for the List-Admins (thanks for all the work
    exerted on our behalf!) and how it fits with the Code-of-Conduct.


    I have trouble imagining ANYONE learning a language like python
    without rapidly being told that python uses indentation instead of
    various ways to detect when a body of text is considered a single
    composite item.

    And code like their example is also nonsense:

    print(var)
    print(var)
    print(var)

    Another way to look at that post, and what the author may have meant; is
    that the final print(), incorrectly indented in the OP, could have been
    written with three different indentations, and thus have three very
    different effects (cf that they are all to be used, as-is).
    --
    Regards,
    =dn
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mladen Gogala@21:1/5 to All on Sat Aug 6 00:29:19 2022
    On Fri, 5 Aug 2022 08:34:45 +0100, ojomooluwatolami675 wrote:

    Hello, I’m new to learning python and I stumbled upon a question nested loops. This is the question below. Can you please how they arrived at 9
    as the answer. Thanks

    var = 0 for i in range(3):
    for j in range(-2,-7,-2):
    var += 1
    print(var)

    Sent from my iPhone

    That's simple. Number 9 itself is equal to 3*3. Inner loop executes 3
    times for each of the 3 executions of the outer loop.
    PS:
    The reply is intentionally written in such a way that it cannot be used as
    an answer to a homework question. You'll have to work out the details
    yourself.

    --
    Mladen Gogala
    Database Consultant
    https://dbwhisperer.wordpress.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mladen Gogala@21:1/5 to All on Sat Aug 6 03:17:21 2022
    On Fri, 5 Aug 2022 10:56:34 +0100, GB wrote:

    As a Python beginner, I find that Python is annoyingly picky about
    indents. And, the significance of indents is a bit of a minefield for beginners.

    That reminds me of my youth, when I was doing another language where indentation
    was important. The language name was COBOL, which stands for "Completely Outdated
    Badly Overused Language". COBOL was (and still is) a beauty, especially with the
    addition of CICS and DL/1.
    Python is, in some spiritual sense, a scripting successor to COBOL. Some hippies at
    Bell Labs, I believe that the names are Thompson, Kernighan and Ritchie, came up
    with enclosing blocks of statements to be executed together within curly braces.
    Those hippies did it precisely to avoid messing up the indentation, as it used to
    happen far too often in the first procedural languages like Fortran, PL/1 and COBOL.
    However, the pure nostalgia brought the indentation back, in the big way. That is
    one of the reasons why democracy isn't a perfect system, as was well known to our
    founding fathers. Simple majority rule can sometimes ruin a good thing and make things worse for everyone. Welcome to Python, scripting language accepted by the
    vast majority of scripters.
    The main virtue of Python is that it is consistently object oriented. However, object orientation itself is a disaster of biblical proportions:

    https://developers.slashdot.org/story/19/07/22/0426201/is-object-oriented-programming-a-trillion-dollar-disaster
    https://betterprogramming.pub/object-oriented-programming-the-trillion-dollar-disaster-92a4b666c7c7

    So, we have the programming language which claims a consistent implementation of a
    very suspect programming methodology at best as its main advantage. And true to the
    form, the indentation is back. Python should be renamed to "Critical Programming
    Theory".

    PS:
    I was forced to learn Python by the manager who said "we don't do Perl in this company".
    Since scripting is an unavoidable part of the DBA job, I had to learn the COBOL of the
    scripting languages. One can only hope that the messiah will return and make the curly
    braces popular again. Until then I too will be suffering under the yolk of the Guido van
    Rossum's monstrosity.

    --
    Mladen Gogala
    Database Consultant
    https://dbwhisperer.wordpress.com

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Stromberg@21:1/5 to All on Fri Aug 5 20:53:03 2022
    On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards <grant.b.edwards@gmail.com> wrote:

    In C, this doesn't do what it looks like it's supposed to do.

    if (foo)
    do_this();
    and_this();
    then_do_this();

    It's been quite a while since I used C, but with the right compiler
    flag(s), I think this may be a thing of the past when compiling with gcc: https://developers.redhat.com/blog/2016/02/26/gcc-6-wmisleading-indentation-vs-goto-fail

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to Dan Stromberg on Sat Aug 6 14:01:13 2022
    On Sat, 6 Aug 2022 at 13:54, Dan Stromberg <drsalists@gmail.com> wrote:

    On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards <grant.b.edwards@gmail.com> wrote:

    In C, this doesn't do what it looks like it's supposed to do.

    if (foo)
    do_this();
    and_this();
    then_do_this();

    It's been quite a while since I used C, but with the right compiler
    flag(s), I think this may be a thing of the past when compiling with gcc: https://developers.redhat.com/blog/2016/02/26/gcc-6-wmisleading-indentation-vs-goto-fail

    Ah yes, because compiler warnings are always viewed and acted upon.

    Have you ever watched the compilation of a large open-source project,
    done using the project's own build system and therefore the team's
    preferred warning settings? It's normal to have such a spew of
    warnings that you can't find anything interesting, or to have new
    warnings in new versions of GCC be utterly useless for the same
    reason.

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Damon@21:1/5 to Chris Angelico on Sat Aug 6 08:06:40 2022
    On 8/6/22 12:01 AM, Chris Angelico wrote:
    On Sat, 6 Aug 2022 at 13:54, Dan Stromberg <drsalists@gmail.com> wrote:
    On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards <grant.b.edwards@gmail.com>
    wrote:

    In C, this doesn't do what it looks like it's supposed to do.

    if (foo)
    do_this();
    and_this();
    then_do_this();

    It's been quite a while since I used C, but with the right compiler
    flag(s), I think this may be a thing of the past when compiling with gcc:
    https://developers.redhat.com/blog/2016/02/26/gcc-6-wmisleading-indentation-vs-goto-fail
    Ah yes, because compiler warnings are always viewed and acted upon.

    Have you ever watched the compilation of a large open-source project,
    done using the project's own build system and therefore the team's
    preferred warning settings? It's normal to have such a spew of
    warnings that you can't find anything interesting, or to have new
    warnings in new versions of GCC be utterly useless for the same
    reason.

    ChrisA

    You make it so you HAVE to fix the warning by adding the option to make warnings into errors.

    This does mean that you need to fix all the warnings that don't actually
    mean anything,

    Good code shouldn't generate many warnings, either you have warnings
    enabled that you don't care about, or your code is doing things you have
    told the complier you shouldn't do.

    --
    Richard Damon

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to Richard Damon on Sat Aug 6 22:12:21 2022
    On Sat, 6 Aug 2022 at 22:08, Richard Damon <Richard@damon-family.org> wrote:

    On 8/6/22 12:01 AM, Chris Angelico wrote:
    On Sat, 6 Aug 2022 at 13:54, Dan Stromberg <drsalists@gmail.com> wrote:
    On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards <grant.b.edwards@gmail.com> >> wrote:

    In C, this doesn't do what it looks like it's supposed to do.

    if (foo)
    do_this();
    and_this();
    then_do_this();

    It's been quite a while since I used C, but with the right compiler
    flag(s), I think this may be a thing of the past when compiling with gcc: >> https://developers.redhat.com/blog/2016/02/26/gcc-6-wmisleading-indentation-vs-goto-fail
    Ah yes, because compiler warnings are always viewed and acted upon.

    Have you ever watched the compilation of a large open-source project,
    done using the project's own build system and therefore the team's preferred warning settings? It's normal to have such a spew of
    warnings that you can't find anything interesting, or to have new
    warnings in new versions of GCC be utterly useless for the same
    reason.

    ChrisA

    You make it so you HAVE to fix the warning by adding the option to make warnings into errors.

    This does mean that you need to fix all the warnings that don't actually
    mean anything,

    Good code shouldn't generate many warnings, either you have warnings
    enabled that you don't care about, or your code is doing things you have
    told the complier you shouldn't do.


    I say again: have you ever watched the compilation of a large
    open-source project? You cannot turn warnings into errors, because
    there are ALWAYS warnings. Maybe, once upon a time, the policy was to
    ensure that there were no warnings on any major compiler; but times
    change, compilers add new warnings, new compilers join the club, and
    it becomes practically impossible to prevent warnings. Which, in turn,
    makes all warnings basically meaningless.

    Hmm. I don't think I've ever compiled gcc from source. Maybe I should
    do that, just to see whether gcc itself compiles with no warnings
    under gcc.

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to Richard Damon on Sat Aug 6 22:46:27 2022
    On Sat, 6 Aug 2022 at 22:39, Richard Damon <Richard@damon-family.org> wrote:

    On 8/6/22 8:12 AM, Chris Angelico wrote:
    On Sat, 6 Aug 2022 at 22:08, Richard Damon <Richard@damon-family.org> wrote:
    On 8/6/22 12:01 AM, Chris Angelico wrote:
    On Sat, 6 Aug 2022 at 13:54, Dan Stromberg <drsalists@gmail.com> wrote: >>>> On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards <grant.b.edwards@gmail.com>
    wrote:

    In C, this doesn't do what it looks like it's supposed to do.

    if (foo)
    do_this();
    and_this();
    then_do_this();

    It's been quite a while since I used C, but with the right compiler
    flag(s), I think this may be a thing of the past when compiling with gcc:
    https://developers.redhat.com/blog/2016/02/26/gcc-6-wmisleading-indentation-vs-goto-fail
    Ah yes, because compiler warnings are always viewed and acted upon.

    Have you ever watched the compilation of a large open-source project,
    done using the project's own build system and therefore the team's
    preferred warning settings? It's normal to have such a spew of
    warnings that you can't find anything interesting, or to have new
    warnings in new versions of GCC be utterly useless for the same
    reason.

    ChrisA
    You make it so you HAVE to fix the warning by adding the option to make
    warnings into errors.

    This does mean that you need to fix all the warnings that don't actually >> mean anything,

    Good code shouldn't generate many warnings, either you have warnings
    enabled that you don't care about, or your code is doing things you have >> told the complier you shouldn't do.

    I say again: have you ever watched the compilation of a large
    open-source project? You cannot turn warnings into errors, because
    there are ALWAYS warnings. Maybe, once upon a time, the policy was to ensure that there were no warnings on any major compiler; but times
    change, compilers add new warnings, new compilers join the club, and
    it becomes practically impossible to prevent warnings. Which, in turn, makes all warnings basically meaningless.

    Hmm. I don't think I've ever compiled gcc from source. Maybe I should
    do that, just to see whether gcc itself compiles with no warnings
    under gcc.

    ChrisA

    And for any project, that is a choice THEY made.

    Indeed. So you can't really say "good code shouldn't generate many
    warnings" unless (a) you're saying that lots of projects are made up
    of bad code, or (b) your statement that this is "a thing of the past"
    is flat-out false, because it can only be valid if you assume that
    everyone has that warning enabled, and preferably set to be an error.

    So, for the vast majority of projects out there, indentation errors
    are going to continue to go uncaught by C compilers. It's not "a thing
    of the past" until most projects use the flag, and preferably, the
    flag becomes active by default.

    And for the record, I have seen spurious warnings from *that exact
    flag* in a large project (an image parsing library). Spurious in that
    the code was actually correct, despite the compiler warning about it.

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Damon@21:1/5 to Chris Angelico on Sat Aug 6 08:38:21 2022
    On 8/6/22 8:12 AM, Chris Angelico wrote:
    On Sat, 6 Aug 2022 at 22:08, Richard Damon <Richard@damon-family.org> wrote:
    On 8/6/22 12:01 AM, Chris Angelico wrote:
    On Sat, 6 Aug 2022 at 13:54, Dan Stromberg <drsalists@gmail.com> wrote: >>>> On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards <grant.b.edwards@gmail.com> >>>> wrote:

    In C, this doesn't do what it looks like it's supposed to do.

    if (foo)
    do_this();
    and_this();
    then_do_this();

    It's been quite a while since I used C, but with the right compiler
    flag(s), I think this may be a thing of the past when compiling with gcc: >>>> https://developers.redhat.com/blog/2016/02/26/gcc-6-wmisleading-indentation-vs-goto-fail
    Ah yes, because compiler warnings are always viewed and acted upon.

    Have you ever watched the compilation of a large open-source project,
    done using the project's own build system and therefore the team's
    preferred warning settings? It's normal to have such a spew of
    warnings that you can't find anything interesting, or to have new
    warnings in new versions of GCC be utterly useless for the same
    reason.

    ChrisA
    You make it so you HAVE to fix the warning by adding the option to make
    warnings into errors.

    This does mean that you need to fix all the warnings that don't actually
    mean anything,

    Good code shouldn't generate many warnings, either you have warnings
    enabled that you don't care about, or your code is doing things you have
    told the complier you shouldn't do.

    I say again: have you ever watched the compilation of a large
    open-source project? You cannot turn warnings into errors, because
    there are ALWAYS warnings. Maybe, once upon a time, the policy was to
    ensure that there were no warnings on any major compiler; but times
    change, compilers add new warnings, new compilers join the club, and
    it becomes practically impossible to prevent warnings. Which, in turn,
    makes all warnings basically meaningless.

    Hmm. I don't think I've ever compiled gcc from source. Maybe I should
    do that, just to see whether gcc itself compiles with no warnings
    under gcc.

    ChrisA

    And for any project, that is a choice THEY made.

    For projects where code quality is actually a defined metric, there is
    normally a specified warning level (for a specified set of compilers and versions) that the code needs to compile at least nearly clean at.

    Yes, you can get that ton of warnings when at a higher warning level,
    but that is why you specify the warning level to use, and put the
    specific mitigations/suppressions for the few cases where the code is
    correct, but generates that warning.

    Yes, you can get a lot of warnings with another compiler, but that is
    because you aren't running at the correct warning level for that
    compiler, which is why the set of compilers that you are "warning free"
    on is specified. When you add a new compiler, it may first not be
    warning free until you make the effort (if you ever do) to make it
    warning free for that.

    Major open source projects will have a "toll gate" on the official
    repository that checks that additions keep the code to the standard it
    has established,

    --
    Richard Damon

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to Richard Damon on Sat Aug 6 12:37:26 2022
    This reminds me a bit of how routine spelling checkers and often especially grammar checkers, generate so many suggestions about mistakes as to become ignored. If you are writing using lots of names and jargon that keep getting flagged as errors and they are spelled or used exactly as you want, then it gets to be too annoying and you turn off the feature. Yes, you can sometimes silence some things in a spell checker that allows you to add words to a
    custom dictionary but for now, that dictionary is not known to every application that checks your spelling.

    That can be the nature of the beast. If your compiler decides to warn you
    every time you do a division that you might be dividing by zero because you
    do not perform the test right before that, then you end up with code that
    tests it AGAIN after having arranged for the value to never be zero in the first place, then test it again when you divide something else by it, ...

    I am sure some programming language has some kind of pragma that lets you whisper to the compiler that this variable at this time is guaranteed not to
    be zero, or that the region is in a try/catch zone which will intercept and
    fix the results of a divide by zero error.

    Just an example. And as you say, new or improved compilers can be made to be ever more picky about trying to find possible anomalies.

    Things are useful when they are somewhat manageable. If a compiler things it detects 372 places in your code where the same thing needs to be mentioned, such as reserving space for an object without simultaneously filling it with some contents, then it would be nice if instead of printing ALL of them, it consolidated it into one warning and say you can click on something to see
    the 372 instances.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Chris Angelico
    Sent: Saturday, August 6, 2022 8:12 AM
    To: python-list@python.org
    Subject: Re: Trying to understand nested loops

    On Sat, 6 Aug 2022 at 22:08, Richard Damon <Richard@damon-family.org> wrote:

    On 8/6/22 12:01 AM, Chris Angelico wrote:
    On Sat, 6 Aug 2022 at 13:54, Dan Stromberg <drsalists@gmail.com> wrote:
    On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards
    <grant.b.edwards@gmail.com>
    wrote:

    In C, this doesn't do what it looks like it's supposed to do.

    if (foo)
    do_this();
    and_this();
    then_do_this();

    It's been quite a while since I used C, but with the right compiler
    flag(s), I think this may be a thing of the past when compiling with
    gcc:
    https://developers.redhat.com/blog/2016/02/26/gcc-6-wmisleading-ind
    entation-vs-goto-fail
    Ah yes, because compiler warnings are always viewed and acted upon.

    Have you ever watched the compilation of a large open-source
    project, done using the project's own build system and therefore the
    team's preferred warning settings? It's normal to have such a spew
    of warnings that you can't find anything interesting, or to have new warnings in new versions of GCC be utterly useless for the same
    reason.

    ChrisA

    You make it so you HAVE to fix the warning by adding the option to
    make warnings into errors.

    This does mean that you need to fix all the warnings that don't
    actually mean anything,

    Good code shouldn't generate many warnings, either you have warnings
    enabled that you don't care about, or your code is doing things you
    have told the complier you shouldn't do.


    I say again: have you ever watched the compilation of a large open-source project? You cannot turn warnings into errors, because there are ALWAYS warnings. Maybe, once upon a time, the policy was to ensure that there were
    no warnings on any major compiler; but times change, compilers add new warnings, new compilers join the club, and it becomes practically impossible
    to prevent warnings. Which, in turn, makes all warnings basically
    meaningless.

    Hmm. I don't think I've ever compiled gcc from source. Maybe I should do
    that, just to see whether gcc itself compiles with no warnings under gcc.

    ChrisA
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Dieter Maurer on Sun Aug 7 13:22:18 2022
    "Dieter Maurer" <dieter@handshake.de> writes:
    For future, more complex, questions of this kind,
    you might have a look at the module `pdb` in Python's runtime library.
    It implements a debugger which allows you (among other features)
    to interactively run a program line by line
    and explore the state of all involved variables.

    One also sometimes can use IDLE as a poor-man's debugger!

    For example, a programmer has just started his program,
    and the IDLE shell window shows:

    |===================== RESTART: tmp.py ====================
    |Traceback (most recent call last):
    | File "tmp.py", line 35, in <module>
    | screen[ x ][ y ]= '*'
    |IndexError: list assignment index out of range
    _

    Now, the programmer can enter expressions to show the values
    of "x", "y", and "screen":

    |===================== RESTART: tmp.py ====================
    |Traceback (most recent call last):
    | File "tmp.py", line 35, in <module>
    | screen[ x ][ y ]= '*'
    |IndexError: list assignment index out of range
    x
    |1
    y
    |1
    screen
    |[['*'], [' ...

    (where "..." stands for more output, which was, however,
    omitted in this post).

    (As other's have remarked before: The OP might not read his
    answers here. So with this post I do not address the OP but
    you all.)

    PS: IDLE's shell window also has a menu "Debug" with an
    entry "Debugger". To use this: First select "Debugger" to
    open the debug window, then start your program.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Purgert@21:1/5 to All on Mon Aug 8 11:59:15 2022
    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512

    dn wrote:
    On 06/08/2022 11.41, avi.e.gross@gmail.com wrote:
    I wonder if someone is pulling our leg as they are sending from an
    invalid email address of "GB <NOTsomeone@microsoft.invalid>" which is
    a bit sick.

    There are a number of folk who use evidently false email addresses - the
    OP's had me amused.

    Such 'hiding' is a matter for the List-Admins (thanks for all the work exerted on our behalf!) and how it fits with the Code-of-Conduct.

    Invalid sending addresses (email@somewhere.invalid) are a standard
    practice in Usenet, to combat bots scraping posts for email addresses (remember, Usenet predates basically all spam prevention tech).

    As there is a gateway between the mailing lists and Usenet, I *imagine*
    that the use of said invalid addresses are within the rules -- I mean,
    if they weren't, the maintainers wouldn't keep the two lists
    connected.


    -----BEGIN PGP SIGNATURE-----

    iQIzBAEBCgAdFiEE3asj+xn6fYUcweBnbWVw5UznKGAFAmLw+rkACgkQbWVw5Uzn KGBT4A/8DR8GWlEgZhcoaLYTnQCfBv8YmykUxQ69/Xwf7o34S/ObtN0WTapgEBkB xamJHzFKENVeOoFwNgWkAaLSfOm2704DqO4vEJBZmCGrPtLTjHmpQuIcg2c+cjwz EEaYCuWmQZrviFS9ZeWX4FIMX9IlZ3Sgy7e/qHvdI5jeclw4oltYdRxVO3h9WylM BXn3Lvqntw+/5xV3vI/B2SODBTkB8a4D0vC64a3NwGqA3eUkyZrJYlVX8igubBwJ /sDLTy9EOK7wmokoXIHjj7KN+s5bC8idUN/V6DJiE6Z3vU0AOujKsw8jyQbndP9d 7da3gDLECMTHTFuKkj8kWC005aaWdM+GYzm1nofQC0jpINCP88IVce9curm11IQa AVWmxNBuGtLh8E3iE5WaydkgwZJXAll2cewOtzyJ0H8qeMwcqtL7hcKwdVPSzSYG JDqcbthDAzJg/PXcLjBHidXNZQ1BhyLw9ySzf+/7buiSsMdHuYZEohHXH4ybRMtL hlg6r09b5nDbKD7C9hVfL21+mogcX9t+LehsqiPLXssyMHRpTmGRzQ+CBySg5QaV gXshFJxRqvp9UtL+xw/wNL3wODsaVTU430qSKUI1ov7ClqcUXvEP5cbmKa9ufJ/J 8iDSbAP2B54pGyF9hfF0f8h267bZy13gWWqBqiFoCBZcVkaC/Jo=
    =6yDi
    -----END PGP SIGNATURE-----

    --
    |_|O|_|
    |_|_|O| Github: https://github.com/dpurgert
    |O|O|O| PGP: DDAB 23FB 19FA 7D85 1CC1 E067 6D65 70E5 4CE7 2860

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From GB@21:1/5 to Dan Purgert on Mon Aug 8 15:42:09 2022
    On 08/08/2022 12:59, Dan Purgert wrote:
    dn wrote:
    On 06/08/2022 11.41, avi.e.gross@gmail.com wrote:
    I wonder if someone is pulling our leg as they are sending from an
    invalid email address of "GB <NOTsomeone@microsoft.invalid>" which is
    a bit sick.

    There are a number of folk who use evidently false email addresses - the
    OP's had me amused.

    Such 'hiding' is a matter for the List-Admins (thanks for all the work
    exerted on our behalf!) and how it fits with the Code-of-Conduct.

    Invalid sending addresses (email@somewhere.invalid) are a standard
    practice in Usenet, to combat bots scraping posts for email addresses (remember, Usenet predates basically all spam prevention tech).

    As there is a gateway between the mailing lists and Usenet, I *imagine*
    that the use of said invalid addresses are within the rules -- I mean,
    if they weren't, the maintainers wouldn't keep the two lists
    connected.




    The history in my case is as follows:

    Years ago, I used Outlook Express, and, for setting up NG access, they suggested an example email address: someone@microsoft.com.

    I did not want to give my true email address, lest it be 'scraped', so I
    used: NOTsomeone@microsoft.com. I added the NOT, to avoid misleading
    people.

    Later, I was prevailed upon to change com to invalid.

    List admins? This particular NG appears to be blessedly free of spam,
    but I hadn't realised it is moderated?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)