do while Like Loop in Python
Since there is no do-while loop in python like in C / C++ programming language. The key features of a do-while loop is body of the loop always executes at least once even if the initial condition is FALSE.
do-while loop is very handy when we need to execute body of loop at least once. So, In this article we will discuss about how to achieve do-while like feature in python programming language.
General Strcuture for Emulating do-while Loop in Python
condition = True
# body of loop here
condition = loop_test_condition
condition = True while condition: # body of loop here condition = loop_test_condition
count = 1 condition = True while condition: print('Welcome to python - %d' % count) count = count + 1 condition = count <= 5
Output of above program is:
Welcome to python - 1 Welcome to python - 2 Welcome to python - 3 Welcome to python - 4 Welcome to python - 5