go back to beginning of loop python code example
Example 1: python loop back to start
def main(): #defines the area in indents that will be triggered with main()#
print('hi')
yn = input('Wanna loop back to the start? ')
if yn = 'yes':
main() #loops back to where we defined main#
main() #This starts the main loop, without this, main would just be defined but not run#
Example 2: python exit for loop
# python 3
for x in range(1, 10):
print(x)
if x == 4:
break
# prints 1 to 4