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
  for loop not executing Abendrot47 2 190 Apr-09-2024, 07:14 PM
Last Post: deanhystad
  Re Try loop for "net use..." failures tester_V 10 561 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 339 Feb-17-2024, 12:29 PM
Last Post: deanhystad
  File loop curiously skipping files - FIXED mbk34 10 788 Feb-10-2024, 07:08 AM
Last Post: buran
  Optimise multiply for loop in Python KenBCN 4 475 Feb-06-2024, 06:48 PM
Last Post: Gribouillis
  Basic binary search algorithm - using a while loop Drone4four 1 352 Jan-22-2024, 06:34 PM
Last Post: deanhystad
  loop through csv format from weburl in python maddyad82 3 387 Jan-17-2024, 10:08 PM
Last Post: deanhystad
  Append inside for? johnywhy 10 814 Jan-15-2024, 11:08 PM
Last Post: johnywhy
  Variable definitions inside loop / could be better? gugarciap 2 430 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  UART & I2C slow down a loop trix 4 606 Dec-28-2023, 05:14 PM
Last Post: trix

Forum Jump:

User Panel Messages

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