Python Forum
Running an action only between certain times
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running an action only between certain times
#10
As Gribouillis says, because of your indentation you are doing while..else, not if..else.

while..else is hardly ever used. I see occasionally see for..else used in a program, but I cannot remember the ever seeing while..else. When using "else" in conjunction with a loop, the else code runs only if the loop terminated normally, based on the condition. If the look was terminated by a break, the else block does not run.
i = 1
while i < 5:
    i += 1
else:
    print("while terminated normally")

i = 1
while True:
    i += 1
    if i > 4:
        print("break out of while loop")
        break
else:
    print("while terminated normally")
Output:
while terminated normally break out of while loop
Your code never prints "No Trigger" because the loop never ends.
Reply


Messages In This Thread
RE: Running an action only between certain times - by deanhystad - Mar-15-2023, 04:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pixel color and action Sartre 4 2,160 Apr-13-2023, 03:26 AM
Last Post: Sartre
  Checkbox itens with a button to run action Woogmoog 3 973 Dec-19-2022, 11:54 AM
Last Post: Woogmoog
Question Running an action only if time condition is met alexbca 5 1,371 Oct-27-2022, 02:15 PM
Last Post: alexbca
  Code running many times nad not just one? korenron 4 1,404 Jul-24-2022, 08:12 AM
Last Post: korenron
  rtmidi problem after running the code x times philipbergwerf 1 2,450 Apr-04-2021, 07:07 PM
Last Post: philipbergwerf
  Running Ajax multiple times on button click? CaptainCsaba 1 2,144 Mar-11-2020, 02:17 PM
Last Post: CaptainCsaba
  Have an amount of time to perform and action CookieGamez2018 1 2,972 Dec-21-2018, 07:12 AM
Last Post: Gribouillis
  action on MQTT while long loop is running runboy 4 6,129 Oct-05-2018, 11:57 PM
Last Post: runboy
  Hourly action resetter with threading? alex36540 3 3,368 Jan-10-2018, 07:13 AM
Last Post: Gribouillis
  recursive action elhetch 6 5,322 Jun-06-2017, 04:23 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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