How to use more than one while loop in a python program, to serve 2 different services. I tried to apply while loop but while it executes only the first while loop, it’s also not showing any indentation error.
Here is my code:
You may check this link for multiple while loops:
Hii @11170021
Statements within a while True block continue endlessly and hence the code gets stuck there. If you want to run 2 while loops in the same code, then you’ll have to initiate while loops with a condition. For example:
As you can see the while loop will terminate after 5 iterations. A similar condition satisfying your need will repair you code. The current problem with your code is that after your code enters the second while loop, there is no break for it, so it continues forever.
Hope this helps!
Python While Loop Multiple Conditions To combine two conditional expressions into one while loop, you’ll need to use logical operators. Using 2 while loops in one code u have to mention conditions.so it can run without mentioning it will run endlessly…
In your code in the first while loop, there is a break statement only on the first if statement inside the loop. As you have given while True it will be an infinite loop. To execute the second loop you will need to put break statements in the first while loop to stop it when the desired action is finished. If this does not suit what you are trying to do then you can give conditions in the while statement instead of True to terminate the loop.