Python while loop

Source: Internet
Author: User

While loop
Another loop that differs from the For loop is the while loop, which does not iterate over the elements of the list or tuple, but rather determines whether the loop ends with an expression.
For example, to print an integer no greater than N from 0:
N = 10
x = 0
While x < N:
Print X
x = x + 1
The while loop first evaluates x < N, if true, executes the block of code for the loop body, otherwise, exits the loop.
In the loop, x = x + 1 causes X to increase and eventually exits the loop because X < N is not true.
Without this statement, the while loop always evaluates to True for x < N, it loops indefinitely and becomes a dead loop, so pay special attention to the exit condition of the while loop.

Python while loop

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.