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
  in c# create a loop counting from 0 to 5, consecutively Frankd 19 1,965 Apr-01-2025, 12:46 PM
Last Post: Frankd
  really new to python want to know how to do a loop pentopdmj 6 1,508 Mar-09-2025, 12:59 PM
Last Post: snippsat
  not able to call the variable inside the if/elif function mareeswaran 3 499 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  knowing for loop position in a list medic5678 4 659 Jan-31-2025, 04:19 PM
Last Post: perfringo
  Run this once instead of a loop, do I need the 'calibration' steps? duckredbeard 2 707 Jan-28-2025, 04:55 PM
Last Post: duckredbeard
  Error loop with Chatgpt sportak12 0 481 Jan-14-2025, 12:04 PM
Last Post: sportak12
  How to convert while loop to for loop in my code? tatahuft 4 780 Dec-21-2024, 07:59 AM
Last Post: snippsat
  How to get keep information in a loop ginod 4 852 Dec-11-2024, 01:32 AM
Last Post: deanhystad
  Regarding The For Loop Hudjefa 5 1,426 Nov-15-2024, 01:02 PM
Last Post: deanhystad
  For Loop beginner agoldav 2 689 Nov-05-2024, 12:51 AM
Last Post: agoldav

Forum Jump:

User Panel Messages

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