Skip to content

While Boolean Python | Example code

  • by

Python While loop uses the Boolean value to executes the loop body while the expression evaluates to (boolean) “true”. You can use a variable as a condition for your while loop instead of just while True.

If you don’t set value false then the loop will run for infinite.

while True:
    if ...:

Example While boolean in Python

While Loop or other loops are used for the repeated execution of a code until the desired condition is met.

Python while loop contains a boolean expression and the code inside the loop is repeatedly executed as long as the boolean expression is true.

Run the while until a condition is true example code.

i = 5
while i < 8:
    print('This is while loop')
    i = i+1


While Boolean Python

Do comment if you have any doubts and suggestions on this Python loop code.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *