Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Real Users never know what they want, but they always know when your program doesn't deliver it.


devel / comp.lang.python / Re: Trying to understand nested loops

SubjectAuthor
o Re: Trying to understand nested loopsDan Stromberg

1
Re: Trying to understand nested loops

<mailman.207.1659739863.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19122&group=comp.lang.python#19122

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: drsali...@gmail.com (Dan Stromberg)
Newsgroups: comp.lang.python
Subject: Re: Trying to understand nested loops
Date: Fri, 5 Aug 2022 15:50:49 -0700
Lines: 30
Message-ID: <mailman.207.1659739863.20444.python-list@python.org>
References: <D50821A2-0B73-478B-8898-6858122D27B7@gmail.com>
<CAGGBd_pHikuuYDJmVTdNrxwEeG5H3c5X_8YOmziqhTiU03SB_Q@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de KNscOIhwcXAlr/GBOwUj/Q5Sr9JuqP/FN4UEY3XQfOug==
Return-Path: <drsalists@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=qIPkRSfD;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '2022': 0.05; 'aug': 0.07;
'loops.': 0.07; 'cc:addr:python-list': 0.09; 'subject:Trying':
0.09; 'answer.': 0.16; 'cc:name:python list': 0.16; 'debugger':
0.16; 'flow.': 0.16; 'from:addr:drsalists': 0.16; 'from:name:dan
stromberg': 0.16; 'happening.': 0.16; 'intuition': 0.16; 'nested':
0.16; 'range(3):': 0.16; 'subject:nested': 0.16; 'wrote:': 0.16;
'python': 0.16; 'probably': 0.17; 'cc:addr:python.org': 0.20;
'fri,': 0.22; "what's": 0.22; 'cc:2**0': 0.25; 'question': 0.32;
'message-id:@mail.gmail.com': 0.32; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'change': 0.36; 'received:209.85': 0.37; 'could': 0.38; 'thanks':
0.38; 'received:209': 0.39; 'single': 0.39; 'received:209.85.208':
0.39; 'hello,': 0.40; 'to:': 0.62; 'skip:r 20': 0.64; 'upon':
0.64; 'times': 0.69; "you'll": 0.73; 'stumbled': 0.76; 'var': 0.81
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=LkbJalT2V8S/A3TB8+irXpmrVkTXcByVg5RTrq1rtLw=;
b=qIPkRSfDyBnzAGkTsyCm9lL4fwXuJDF/vLe5Ii7NvMRYCxUByPGPzfoINgskLFxGMH
NQ+iNodmbVF4vUzHdXyOZj1/BA4s94XqZa3dYmb7eeWs+pJLvNhpmDHIaBInCFYJqjEM
IQlf95USKi8Rcw2tjamGJ8cttXUm5ZytNO335zHQdYt5LeNbj0seWY55VqYyg6ebY7Tq
7Ge/i6fAzyEZ8o5u7c68rrwdASTwAPxuOpb6Yej8ns7h7EhuZ6VsAgds8YtcozxlnXow
76JmtE/Gvea56FLiou+eQqKyAyIs14ToKp7EXWlXlW1XBcrWx/aFHdG6sN7J1hGPw3WU
4myg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=LkbJalT2V8S/A3TB8+irXpmrVkTXcByVg5RTrq1rtLw=;
b=mzlTzy41fGMKT4bX1D8bsRZCDYBEE4FF1elpb7SC9Osh055LL6yidMOpAlKtYjXocK
wBjE4GtmbQi68o7xXZLAAst7wVnGc8BuHDuGg6FUmb9is2aA0QMb9TSL5mh8BMP91hhL
mfuD3UN7Z2akQtEz4a02DuujiBCj+3GSh1BMxop2nyZZulQmqzKyKBaKDm4EmO/6E918
ryGpXzhhbEVYf6UL7a4Itr+2IRp+Qz9SESYgVoMa9upze1GHfhr+I23fbTDvV/JGE/a8
xlrRisV0ExQQxHVXJmNjYSDRYQH1/o90aydsZLnJWEhGIp6x1tIsBsY1srzl8e44bABb
7iVg==
X-Gm-Message-State: ACgBeo2n6F5NmQjkaD8wmtYfyQnGz+kw+6b5IOE7ShSbgIf9tlKizxp6
sGMzVvcapZb8lkMVxGD+fBOFCbrV44OB7YBEb7XfidWNVYU=
X-Google-Smtp-Source: AA6agR4gZ9gKjsPoNtZhKNy9eJolnVAjBX8GVcLXe3Vq5CyPcgowGtYmXyvkBkIx8MavmWNAcxdlIGg3rcePGqV4jhE=
X-Received: by 2002:a2e:83c9:0:b0:24d:a95d:7b7a with SMTP id
s9-20020a2e83c9000000b0024da95d7b7amr2632612ljh.254.1659739860830; Fri, 05
Aug 2022 15:51:00 -0700 (PDT)
In-Reply-To: <D50821A2-0B73-478B-8898-6858122D27B7@gmail.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAGGBd_pHikuuYDJmVTdNrxwEeG5H3c5X_8YOmziqhTiU03SB_Q@mail.gmail.com>
X-Mailman-Original-References: <D50821A2-0B73-478B-8898-6858122D27B7@gmail.com>
 by: Dan Stromberg - Fri, 5 Aug 2022 22:50 UTC

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.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor