Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
out and back to loop
#1
Hi everyone, I don't understand how out from a loop while. I have a test loop ho test the contacts GPIO from my raspberry then the contact go to close send email (just one) and when the contact go back to open sand one email (just one) to say what he is open. Meanwhile the test loop continues. now it's worked but he sends as much mail as loop turns. somone can give me idea to solvd thet ? thank you.
Reply
#2
To get out of a loop, you use the break statement:

num = 1
while True:
    print(num)
    num += num
    if num > 100:
        break
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
ok but how I go back to my loop ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code won't break While loop or go back to the input? MrKnd94 2 906 Oct-26-2022, 10:10 AM
Last Post: Larz60+
  "while" loop is looping back too early mangurian 1 1,242 Jan-28-2022, 09:15 AM
Last Post: ibreeden
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 2,883 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes
  How to make loop go back to the beginning if test evaluaes to True. FWendeburg 1 2,797 Feb-13-2019, 01:26 AM
Last Post: stullis

Forum Jump:

User Panel Messages

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