in its most complex formthe while statement consists of header line with test expressiona body of one or more normally indented statementsand an optional else part that is executed if control exits the loop without break statement being encountered python keeps evaluating the test at the top and executing the statements nested in the loop body until the test returns false valuewhile teststatements elsestatements loop test loop body optional else run if didn' exit loop with break examples to illustratelet' look at few simple while loops in action the firstwhich consists of print statement nested in while loopjust prints message forever recall that true is just custom version of the integer and always stands for boolean true valuebecause the test is always truepython keeps executing the body foreveror until you stop its execution this sort of behavior is usually called an infinite loop--it' not really immortalbut you may need ctrl- key combination to forcibly terminate onewhile trueprint('type ctrl- to stop me!'the next example keeps slicing off the first character of string until the string is empty and hence false it' typical to test an object directly like this instead of using the more verbose equivalent (while !'':later in this we'll see other ways to step through the items in string more easily with for loop 'spamwhile xprint(xend=' [ :spam pam am while is not empty in use print xstrip first character off note the end=keyword argument used here to place all outputs on the same line separated by spacesee if you've forgotten why this works as it does this may leave your input prompt in an odd state at the end of your outputtype enter to reset python readersalso remember to use trailing comma instead of end in the prints like this the following code counts from the value of up tobut not includingb we'll also see an easier way to do this with python for loop and the built-in range function latera= = while bprint(aend=' + while and for loops one way to code counter loops ora