print ("the sum is"sumwhen you run the programthe output will beenter the sum is in the above programthe test expression will be true as long as our counter variable is less than or equal to ( in our programwe need to increase the value of the counter variable in the body of the loop this is very important failing to do so will result in an infinite loop (never-ending loopwhile loop with elsesame as with for loopswhile loops can also have an optional else block the else part is executed if the condition in the while loop evaluates to false the while loop can be terminated with break statement in such casesthe else part is ignored hencea while loop' else part runs if no break occurs and the condition is false example'''example to illustrate the use of else statement with the while loop''counter while counter print ("inside loop"counter counter elseprint ("inside else"outputinside loop inside loop inside loop inside else herewe use counter variable to print the string inside loop three times on the fourth iterationthe condition in while becomes false hencethe else part is executed nested loopsloops can be nested in python similar to nested loops in other programming languages