0
Please explain given code
2 Antworten
+ 1
# print Hello world! in terminal
print('Hello world!')
# sets variable i to equal 0
i = 0
# starting loop with while true statement. the “True” after “while” is the condition for the loop to continue. you can use any condition statement - i < 5; or 1 == 1; etc.
while True:
# prints the value of i
print( i)
# adds 1 to the variable i. when i is 0, it will now become 1 (0+1), when 1 it will be 2 (1+1), and so on.
i = i + 1
# if statement when i is equal yo or greater than 5 to execute code within if statement.
if i >= 5:
# when i is greater than or equal to 5 print “breaking”
print("breaking")
# after print break or exit code.
break
# exit while loop and print finished
print(""""""finished""""")
i hope that is helpful.
0
Thanks ❤️