![]() |
We have given a list of strings and we need to emulate the list of strings using the Do-while loop and print the result. In this article, we will take a list of strings and then emulate it using a Do-while loop.
Example: Input : ["horje", "C++", "Java", "Python"] How to Emulate a Do-while loop in Python?Below, are the methods to Emulate a Do-while loop in Python.
Emulate a Do-while loop Using a Conditional BreakIn this example, the below code creates a list of strings and enters an infinite loop. Within the loop, it prints each string from the list once. It then breaks out of the loop and prints a message confirming the loop has exited.
Output Strings in the list: horje C++ Java Python C MachineLearning Loop has exited. Emulate a Do-while loop Using a Flag VariableIn this example, below code starts by printing a message indicating that it’s going to display the strings in the list. It then employs a while loop with a flag variable to iterate over each string in the list and print it. The loop continues until the index exceeds the length of the list, at which point the flag is set to False, and the loop terminates.
Output Strings in the list: horje C++ Java Python C MachineLearning Loop has exited. |
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 17 |