Python Forum
Loop inside loop inside loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop inside loop inside loop
#1
Hey guys

How to break nested loop?
Reply
#2
can you show sample code and explain better what you want (e.g. break out of the inner most loop into upper level, or break out of all netsed loops, etc.), because your setup is not very clear. Otherwise the answer is to use break.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Maybe one of my earlier answers to similar question helps.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
(Mar-16-2020, 09:52 AM)buran Wrote: can you show sample code and explain better what you want (e.g. break out of the inner most loop into upper level, or break out of all netsed loops, etc.), because your setup is not very clear. Otherwise the answer is to use break.

elements = "qwertyuiop"
elements_list = list(elements)

password = input("enter: ")




for a in elements_list:
////for b in elements_list:
////////for c in elements_list:
////////////print(a+b+c)

////////////if a+b+c == password:
////////////////break

Reply
#5
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.

what do you want to achieve? Why do you do all these weird things? If you want to check string is present in list of strings:

passwords = ['week_pass', 'fEaPzy0M8#2`pHNS']
password = input('Enter password:')
if password in passwords:
    print('Correct password')
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable being erased inside of if statement deusablutum 8 547 Jun-15-2024, 07:00 PM
Last Post: ndc85430
  Need an alternative to brute force optimization loop jmbonni 5 1,543 Jun-05-2024, 02:21 AM
Last Post: stevejobb
  Need help with a while loop ampereap 4 299 May-31-2024, 02:25 PM
Last Post: ampereap
  problem program runs in a loop jasserin 0 238 May-18-2024, 03:07 PM
Last Post: jasserin
  [SOLVED] Loop through directories and files one level down? Winfried 3 478 Apr-28-2024, 02:31 PM
Last Post: Gribouillis
  Loop through all files in a directory? Winfried 10 923 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
  for loop not executing Abendrot47 2 409 Apr-09-2024, 07:14 PM
Last Post: deanhystad
  Re Try loop for "net use..." failures tester_V 10 895 Mar-02-2024, 08:15 AM
Last Post: tester_V
  How to receive two passed cmdline parameters and access them inside a Python script? pstein 2 523 Feb-17-2024, 12:29 PM
Last Post: deanhystad
  File loop curiously skipping files - FIXED mbk34 10 1,178 Feb-10-2024, 07:08 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020