Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (394.83 KB, 2 trang )
while loop
While loops, like the For loops, are used for repeating specific block of codes. The "while" loop is capable of anything that
the "for" loop can do. But unlike a for loop, the while loop will not run n times, but until a defined condition is no longer met.
If the condition is initially false, the loop body will not be executed at all.
The syntax of this loop is:
while (condition):
statement_1
statement_2
...
...
statement_n
Let's make our examples;
In [1]: count = 0
while (count < 10):
print ('The count is:',count)
count += 1
print("It's done!")
The count is:
The count is:
The count is:
The count is:
The count is:
The count is:
The count is:
The count is:
The count is:
The count is:
It's done!
0