Vinodbhai Patel
Vinodbhai Patel

Reputation: 11

How would I stop a if loop after execute one time?

if len(columns) > 0:
    #print "IF LOOP"
    for index in range(len(columns)):
          txt = columns[index]
          msg = msg + txt + '  Declared'
    msg = ' '.join(msg.split())
    notifier(msg)

I created one cronjob in my program but i want to stop execute this loop after one time.

Suppose i create new variable in starting and after one time execute this loop assign False so if loop checks two conditions if Variable is False so it will not execute this statement....

but every time cronjob creates new objects so what is the solution for this to stop execute this statement in if loop after one time executed.

Upvotes: 0

Views: 1136

Answers (1)

boot-scootin
boot-scootin

Reputation: 12515

Use break if you want to exit a loop (either while or for). A very simple example:

count = 0

for _ in range(1000):
    count += 1
    if count == 1:
        break

Upvotes: 1

Related Questions