Trending November 2023 # Do While Loop In Python # Suggested December 2023 # Top 20 Popular

You are reading the article Do While Loop In Python updated in November 2023 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested December 2023 Do While Loop In Python

Introduction to Do While Loop in Python

Web development, programming languages, Software testing & others

Flowchart of Do-While Loop

In most of the computer programming languages, unlike while loops which test the loop condition at the top of the loop, the do-while loop plays a role of control flow statement similar to while loop, which executes the block once and repeats the execution of block based on the condition given in the while loop the end.

Syntax of do-while

do { Statement(s) } while (condition);

In this syntax, the condition appears at the end of the loop, so the statements in the loop execute at least once before the condition is checked. In a while loop, we check it at the beginning of the loop. If the condition is true it jumps to do, and the statements in the loop are again executed. This is repeated until the condition is false. While loop in python has the syntax of the form:

Syntax of while 

while expression: statement (s)

We are used to doing while loops in all basic languages, and we want it in python. The do-while loop is important because it executes at least once before the condition is checked. Though python cannot do it explicitly, we can do it in the following way.

Syntax  while if

while True: # statement (s) If not condition: break;

In python, while loop repeatedly executes the statements in the loop if the condition is true. In a while loop, the test condition is checked first, and if it is true, then the block of statements inside the loop is executed. After one iteration, again, the test condition is checked, and this process is continued until the test condition evaluates to false. The do-while loop which is not in python it can be done by the above syntax using while loop with break/if /continue statements. In this, if the condition is true, then while statements are executed, if not true, another condition is checked by if loop and the statements in it are executed. The break statement is used to bring the program control out of the if loop. In other words, the break is used to abort the current execution of the program.


i = 1 while True: print(i) i = i + 1 break

In the python body of the while, the loop is determined through indentation. As there is no proper indentation for specifying do while loop in python, therefore there is no do-while loop in python, but it is done with while loop itself. The body of the while loop starts with indentation, and as soon as the unindented line is found, then that is marked as the end of the loop.

Conclusion – Do While Loop in Python

As we are very used to do while loop in all other languages, it will first execute statements and then check for the conditions. In python, we also want it to be done, but it cannot as it will not fit the indentation pattern of the python other statements. So in Python, it can be done with a while statement using the break/continue/if statements if the while condition is not satisfied, which is similar to do while loop as in other languages. The while loop in python first checks for condition, and then the block is executed if the condition is true. The block is executed repeatedly until the condition is evaluated to false. Thus, in python, we can use a while loop with if/break/continue statements that are indented, but if we use do-while, it does not fit the indentation rule. Therefore we cannot use the do-while loop in python.

Recommended Articles

This is a guide to Do while loop in python. Here we discuss the flowchart of Do While Loop in Python with the syntax and example. You may also look at the following article to learn more-

You're reading Do While Loop In Python

How Do I Write Json In Python?

In this article, we will learn different types of methods to write JSON in python.

Conversion Rules

When converting a Python object to JSON data, the dump() method follows the conversion rules listed below −

Writing Dictionary into a JSON File

The function of json.dump() is to arrange a Python object into a JSON formatted stream into the specified file.

Syntax dump(obj, fp, *, skipkeys=False, check_circular=True, allow_nan=True, indent=None, separators=None, default=None, sort_keys=False, **kw) Parameters

obj − obj is known as object that arranges as a JSON formatted stream.

fp −the fp also know as file object will store JSON data.

skipkeys − The default value is False. It ignores the Keys of dict that are not of a basic type. Orelse, it will throw a TypeError.

check_circular − It’s default value is True. It’s main task is to perform circular reference check for container types. This sometimes get the output result in an OverflowError.

allow_nan − It’s e default value is True. If false, serializing out-of-range float values will result in a chúng tôi uses JavaScript equivalents like -NaN, Infinity, -Infinity by default.

indent − It is used for good printing with a specified order.

separators − These are the ones used in the JSON.

default − this function is called when an object fails to serialized. It either returns object’s JSON-encoded version or throw a TypeError. If no type is given, a TypeError is defaulty thrown.

sort_keys − It’s default value is False. If true, the dictionaries’ output will be ordered/sorted by key.


The following program converts the given dictionary to a JSON file using the json.dump() function −

# importing json module import json # creating a dictionary inputDict = { "website": "Tutorialspoint", "authorName": "xyz", "Age": 25, "Address": "hyderabad", "pincode":"503004" } # opening a JSON file in write mode with open('outputfile.json', 'w') as json_file: # writing the dictionary data into the corresponding JSON file json.dump(inputDict, json_file) Output

On executing, the above program will generate the following output −

{"website": "Tutorialspoint", "authorName": "xyz", "Age": 25, "Address": "hyderabad", "pincode": "503004"}

A file named outputfile.json is created containing the above dictionary data.

Using the Indent Parameter

Use the indent parameter of the method dump() for attractive printing.


The following program converts the given dictionary to a pretty JSON file with indentation using the json.dump() function and indent argument −

# importing JSON module import json # creating a dictionary inputDict = { "website": "Tutorialspoint", "authorName": "xyz", "Age": 25, "Address": "hyderabad", "pincode":"503004" } # opening a JSON file in write mode with open('outputfile.json', 'w') as json_file: # writing the dictionary data into the corresponding JSON file # by adding indent parameter to make it attractive with proper indentation json.dump(inputDict, json_file, indent=5) Output

On executing, the above program will generate the following output −

{ "website": "Tutorialspoint", "authorName": "xyz", "Age": 25, "Address": "hyderabad", "pincode": "503004" }

A file named outputfile.json is created containing the above dictionary data with a proper indentation for making it more pretty.

Sorting the Keys in JSON

We can sort the keys of a dictionary alphabetically using the sort_keys = True parameter.

The following program converts the given dictionary to a sorted JSON file with indentation using the json.dump() function and sort_keys argument−

# importing JSON module import json # creating a dictionary inputDict = { "website": "Tutorialspoint", "authorName": "xyz", "Age": 25, "Address": "hyderabad", "pincode":"503004" } # opening a JSON file in write mode with open('outputfile.json', 'w') as json_file: # writing the dictionary data into the corresponding JSON file # indent parameter- to make it attractive with proper indentation # sort_keys- sorts the dictionary keys alphabetically json.dump(inputDict, json_file, indent=5, sort_keys=True) Output { "Address": "hyderabad", "Age": 25, "authorName": "xyz", "pincode": "503004", "website": "Tutorialspoint" }

The keys are now sorted alphabetically, as seen above.

Separators are an additional argument that can be used. In this, you can use any separator you like (“, “, “: “, “,”, “:”).

Converting Python List to JSON Example

The following program converts the python list to JSON string using dumps() function −

# importing JSON module import json # input list inputList = [2, 4, 6, 7] # converting input list into JSON string using dumps() function jsonString = json.dumps(inputList) # printing the resultant JSON string print(jsonString) # printing the type of resultant JSON string print(type(jsonString)) Output [2, 4, 6, 7] Converting Directories Python List to JSON Example

The following program converts the Directories python list to JSON string. using dumps() function −

# importing json module import json # input list of dictionaries list_dict = [{'x':10, 'y':20, 'z':30}, {'p':40, 'q':50}] # converting list of dictionaries into json string jsonData = json.dumps(list_dict) # printing the JSON data print(jsonData) Output [{"x": 10, "y": 20, "z": 30}, {"p": 40, "q": 50}] Converting Python List of Lists to JSON Example

The following program converts the Python List of Lists to JSON string using dumps() function −

# importing JSON module import json # input list of lists list_of_list = [[{'x':10, 'y':20, 'z':30}], [{'p':40, 'q':50}]] # converting a list of list into JSON string jsonString = json.dumps(list_of_list) # printing the resultant JSON string print(jsonString) Output

[[{"x": 10, "y": 20, "z": 30}], [{"p": 40, "q": 50}]]


This article contains a variety of techniques for converting various data formats to JSON files, JSON strings, etc. json.dumps(), which is used to convert any form of iterable to JSON, has also been covered in depth.

How Do I Become An Expert Python Programmer?

Learning Beginners Topics

In this section, any new beginner should concentrate on fundamental programming concepts and properly grasp the basic components of programming.

The following is the list of recommendations for a beginner to become an expert python programmer −

Variables − You must understand how variables work, the different types of variables, the scope of variables, and why we even need variables in programming. You can also learn about mutable and immutable data types, which are selfexplanatory.

Operators − Operators are important in programming since they are the tools that are used for computation, variable assignment, condition evaluation, and loops.

Conditions − When it comes to decision-making conditions are dominant. You will need to understand Boolean conditions, conditional chaining, and the statements used to check conditions in this section. This is commonly associated with loops and iteration. You must be familiar with the various loops accessible in the language, such as for and while loops.

Basic Data Structures − Data structures play a key role in every program. There are various other data structures to learn, but the primary focus should be on lists, sets, dictionaries, and tuples.

Functions − Functions are important in any program. The combination of many functions within your programs is what causes the program to behave as expected.

Basic understanding of IO operations − This is not a difficult task. How to read from a text file is the concept to understand. How do you save a text file? Can you read CSV files? These are things you may need to accomplish, especially if you want to create real-world apps or store something in a file. So it will be the fundamental section for you.

Unit testing − You must know how to perform test-driven development in Python or any other programming language.

It is essential that you practice the skills in this area since mastering or having a thorough understanding of the basics will make your Python journey easier.

Learning Intermediate Topics

The following are the main concepts that an intermediate python programmer must learn −

Object-oriented programming (OOP)

Yes, it seems to be a very popular word. It requires a thorough understanding of classes, objects, and many concepts like instantiation, inheritance, abstraction, properties, and others. Learning this will help you a lot. If you only remember one thing from this intermediate level, it’s that you need a solid foundation in object-oriented programming in order to understand anything above this level.

Design patterns

When it comes to object-oriented programming, design patterns and best practices are essential.

Data structures

After you’ve mastered object-oriented, you must learn about data structures. Explore topics like queues, hash maps, and stacks, to name a few. These subjects will be discussed, and knowing the efficiency and temporal complexity in big O notation is crucial. Don’t be frightened if you don’t grasp some of the terminologies. You will make it.


So list and dictionary comprehensions are extremely cool, fancy-looking things in Python. They are techniques for writing one-liners (writing a whole independent statement in one line).

Lambda functions

These are anonymous functions. These functions are commonly found in collection modules, but they are not limited to them. Learn more about the Lambda function and its finest applications.

Inheritance Dunder Methods

If you’ve ever seen def__init__ or used a function that looks the same, that’s an example of a Python special method. These will be simple to learn once you’ve mastered the functions in the beginner section.


This is one of Python’s best features because pip is a package manager that allows you to include third-party modules in your codes. This is related to learning about Python environments such as Anaconda and how to use them. You will also learn how to design and use your own modules in this section.

Learning Advanced Topic Decorators

They are associated with object-oriented programming. In layman’s terms, they decorate a function or method.


Generators are a method to efficiently use memory in Python. Assume you’re generating a collection rather than the whole thing. If you just need access to one item from that collection at a time, you can generate one item at a time. It does not have to be one item; it may be two or three. A generator can be used for this purpose.

Context managers

Context managers are usually indicators of a cleanup operation that occurs after you exit/break the context manager.

Metaclasses Concurrency and parallelism

This needs its own article because it is a really long subject to get into.

Concurrency is the task of running and managing numerous computations at the same time, whereas parallelism is the task of running several computations simultaneously.


This might definitely be classified as expert or master level, but Cython is essentially how you develop C code that interacts with Python. So, if I have a really performance-heavy piece of code or operation that needs to be done rapidly and I don’t trust Python to do it for me, I can write it in C and then link it up to Python using a module called Cython.

Learning Expert Topics

You most likely have a vision of what you want to do at this stage. Consider it specialization. You can pursue a career in data science, machine learning, artificial intelligence (AI), or full-time web development. To be honest, each specialist delves deeper into a specific path chosen. There isn’t anything to write about that is relevant at the expert level. Every particular route necessitates more involvement, which you, as the developer, will select.

We cannot offer you a timetable for when you will arrive. It everything usually comes down to your dedication and passion.


How To Fix Discord Update Failed Loop In Windows 11

Discord is a popular communication platform for gamers. Like any other software, Discord requires regular updates to ensure an optimal experience for its users. However, sometimes, you might experience an error where Discord gets stuck in an update failed loop, preventing you from accessing the application.

In this article, let’s see how you can resolve the Discord update failed loop error on your Windows 11 computer.

For you, we’ve compiled a list of thirteen troubleshooting methods, using which you can stop Discord from entering the update failing loop. However, before moving to the methods, we suggest you try some basic fixes like restarting your computer and the internet router, disabling VPN or proxies if you’re using any.

Also, before using any of the mentioned methods, ensure Discord is not running in the background on your Windows 11 PC.

1. Check Server Status

The first thing to do is to check if the problem is on your end or if there’s an issue on the application’s side. Luckily, Discord has its status page where you can see everything from system status to system metrics and details of past incidents like when they happened, their current report, etc.

To ensure the problem is not on your end, visit Discord’s official status page, and check for server outrages. If the problem is with Discord’s server, you can do nothing but wait for the developers to fix it, but if not, try other fixes on the list.

2. Restart Discord

When the servers are up and running, it indicates that the problem is on your side. Therefore, to fix it, try restarting Discord, as in many cases, we’ve seen how a restart has solved complicated software-related problems. Follow these steps to re-launch Discord on a Windows 11 computer:

4. Now, launch the Discord app.

3. Run Discord as an Administrator

Launching Discord with administrator privileges can sometimes stop the update failed loop in Windows 11. When you run a program as an administrator, you grant elevated permissions to the program, allowing it to tweak system files and settings that a regular user may not have permission to modify.

Here’s how you can run Discord as an administrator on Windows 11:

1. Close the application as we did in method 2.

2. Search for Discord in the Start Menu’s search bar.

A corrupted update file can also be the reason behind the Discord update failed loop on your computer. To fix the corrupted file, rename it. When you change the file’s name and launch Discord, it won’t use the renamed file, assuming it’s not in the folder.

But instead, it’ll download a new update file from the internet to replace the missing file, thus fixing your update-related error. Follow these steps to rename the Discord’s update file in Windows 11:

1. Close the app by quitting it from the hidden icons menu.

2. Open the File Manager app and paste the following path in the address bar.


3. Navigate to the Discord folder.

4. Change the name of the update file to anything you want, and launch Discord.

5. Clear Discord Cache

When you’re using Discord, it stores some of its data in a cache folder. This cache folder has temporary files that Discord needs to run smoothly. However, if the cache becomes corrupted, it can cause problems with Discord, like giving an update failed loop error.

When you clear the Discord cache, you’re technically deleting all the temporary files, and now Discord will create new files in the cache folder for its use. As the files are newly generated, they shouldn’t be damaged, and doing this may stop the app from getting into the update failed loop.

Therefore, try this method and check if it solves your problem. Also, you can refer to our guide on clearing the Discord cache if you need assistance.

Incorrect date and time settings can cause the Discord app to get stuck in the update failed loop. To fix this, you can change your computer’s date and time settings to set automatically. It is a simple fix that has worked for many Discord users.

Here’s how you can tweak the date and time settings on your computer:

1. Exit Discord as we did in method 2.

2. Press Win + I to open the Settings app.

4. Go to the Date & time section.

After changing the settings, restart your computer and then launch Discord.

7. Turn Off Real Time Protection

In some cases, Windows 11’s Virus and Threat protection program may mistakenly flag Discord’s chúng tôi file as malicious, preventing them from launching and downloading/installing updates. By temporarily turning off the real-time protection settings, you can check if it’s causing the problem and then take appropriate action.

Follow these steps to turn off real-time protection on your Windows 11 PC:

1. Open the Settings app on your computer.

3. Select Windows Security.

4. Choose Virus & threat protection under the Protection areas section.

6. Turn off the toggle for Real-time protection.

That’s it! Now, you’ve successfully disabled the real-time protection on your Windows 11 PC. Now launch Discord and check if the issues persist. Also, remember that disabling this setting should only be a temporary measure for troubleshooting, and you should re-enable it once the issue is resolved.

8. Disable Third-Party Antivirus

Third-party antivirus software has a history of conflicting with other system apps. When an antivirus program flags Discord’s chúng tôi file as a threat, it may quarantine or block it from running, causing an update failed loop in the Discord app.

By disabling the third-party antivirus, you allow the update file to run without any conflict, which may further result in resolving the update failed loop error.

9. Disable Microsoft Defender Firewall

The Windows Defender Firewall protects your system by monitoring and controlling network traffic. However, sometimes, its settings can be overly strict, causing it to block some network-related processes of third-party apps like Discord.

When you temporarily disable the Firewall, you remove any restrictions on Discord’s network connections, allowing the app to connect with the server and download updates. Follow these steps to turn off the Defender Firewall in Windows 11:

1. Open the Windows Security app.

3. Select the network that you’re currently using.

4. Toggle off the Microsoft Defender Firewall.

After turning off the Firewall, open the Discord app and check if the issue persists. If the issue is resolved, enable the Firewall and allow Discord to communicate through the Firewall so that you don’t face the update failed problem again. Here’s how you can do it:

1. Head to the Control Panel on your computer.

10. Reinstall Discord

If none of the methods worked, the last resort is to reinstall Discord on your computer. Reinstalling will replace all the current Discord files with new ones, so if the update failed loop was due to some corrupted file, a complete app reinstall will fix it.

This method is divided into three steps; first, you need to uninstall Discord from your computer, then you delete all the temporary files, and lastly, install the app again. If you need help with the uninstallation or installation part, you can always refer to our guide on uninstalling Discord in Windows 11 and installing Discord in Windows 11.

11. Reset Network Settings

Unconfigured network settings can also be the reason why you’re getting the update failed loop on the Discord app, and in that case, doing a network settings reset can help you fix the error.

Resetting network settings means restoring all the settings to default, which fixes connectivity-related issues. Follow these steps to reset network settings on Windows 11:

1. Open the Settings app on your computer.

3. Select Advanced network settings.

4. Select the Network reset option under the More settings section.

12. Install the Public Beta

The public beta version of Discord is a version of the app that is released before the stable version. It is used to test new features and bug fixes before they are released to the users.

In some cases, installing the public beta version of Discord can fix the update failed loop error. This is because the public beta version may include a fix for the bug that is causing the error. Follow these steps to install the latest public beta on your computer:

1. Uninstall Discord from your system.

2. Head to the Discord download page.

4. After downloading, install and sign in to the app to start using.

Enjoy the Latest Features of Discord on Windows 11

Discord’s update failed loop issue can be frustrating, but by following the steps outlined in this article, you should be able to resolve the problem on your Windows 11 system. But if the issue persists, you can try using the web version of Discord.

Top 10 Python Compilers For Python Developers In 2023

Here are the top 10 python compilers for python developers in 2023 selected by experts.

A python compiler is a program that translates a high-level programming language into a lower-level language so that the assembly can understand and interpret the logical inputs.

Both online and offline python compilers for python developers are available.

Coding, designing, deploying, and troubleshooting development projects, typically on the server-side (or back end), fall under the purview of a Python developer. However, they might also assist businesses with their technological framework.  For beginners, there are many Python compilers in 2023 but the top 10 Python compilers are as follows:


Programiz is free and open-source, meaning that it doesn’t cost anything to get started, making it ideal for beginners. Being immersive, extensible, and flexible, it is an interpreted language of a high level. It has a large community and a large library to continue improving its utility for programmers.


Refactoring, debugging, code analysis, and other powerful specifications are available in Pydev. Unittest integration, PyLint, and other features are all supported by Pydev.

Black-formatted virtual environments and Mypy are made possible with Pydev.

Code folding, syntax highlighting, and support for a variety of other programming languages are all made possible by Pydev. It is compatible with the Django Framework, Jython, and other programming languages.


Over a thousand plugins are supported by PyCharm. We can quickly switch between multiple files. The plugin can be written by developers on their own.

Sublime Text:

It has a “Goto Anything” feature, which allows us to move the cursor to any location we choose. Multiple lines and words can be chosen in sublime text. Its preferences can be altered to meet the needs of a particular project. Its free version is accessible to all. It has a plugin that can highlight text and is excellent for debugging. It supports finds and replaces features more effectively than others. We can work on multiple projects simultaneously without getting lost. It keeps recommending correct syntax.


For each function call, a separate window is displayed. The debugger is extremely user-friendly. The F5, F6, and F7 keys are used. It depicts the function calls and emphasizes the coding error. The code is completed automatically by it. A simple user interface makes it easy to use. Thonny is the best IDE for novices. It takes care of the coding problems caused by other interpreters.

Visual Studio Code:

Python coding, debugging, and other activities are supported by Visual Studio Code, which is light and easy to use. There are two free and paid versions of Visual Studio Code. Advanced features are included in the paid version. It supports a variety of programming languages and has plugins built in. It can be customized to meet individual requirements. It quickly finishes and finds the code.

Jupyter Notebook:

Markdowns are supported in Jupyter notebook, and you can include HTML code in videos and images. It makes editing simple and easy. It is ideal for people who are just starting in the field of data science. We can use data visualization libraries like Seaborn and Matplotlib to show where the code is in the graphs in the same document. The final work can be exported in a variety of formats.


Vim has a very small footprint on memory. It is the hub of command. With just a few commands, we can handle intricate text and related tasks. It stores its configuration in a simple computer file and is extremely configurable. For Vim, number of plug-ins are available. By utilizing these plug-ins, its usability will be enhanced. There will be multiple windows on the screen for the exploitation feature. It also supports multiple buffers in multiple windows. It has multiple tabs that allow figures to be displayed on multiple files. It has options for recording that make it possible to continuously record and play Vim commands.



Nested If Statement In Python

Introduction to Nested IF Statement in Python

Programming has surely come a long way from a simple “Hello World” program to all the modern day’s complex programs. With time new features got added to programming to cater to various needs.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

So we need to introduce some sort of Decision making capability to our programs to make them more robust.

Let us suppose we have a program in which we input a number from the user and check whether it is an even number or an odd number. It is a classic example of using a conditional statement. The following flowchart would help depict it more clearly:-

Examples of Conditional Statements in Python

This is an example of an elementary conditional statement for finding whether a number is even or not.

The following are the different kinds of Conditional Statements in Python: –

if statement

if-else statement

else-if statement

nested if statement

switch statement

In this article, we would focus mainly on Nested If Statements, for which we would have a little introduction of If Statements, and then we would jump to the main topic.

1. If Statements

Syntax: –

Let us look into the details of the syntax of the if-statement.

The most important component is the “if” keyword, which helps us identify an expression to be a conditional statement.

expr: – This signifies the condition, the fulfillment of which would execute the below statement. The expr is basically a Python statement that results in a Boolean value (True or False). The statement for the particular expr will get executed only if the value for the expr is True.

statement: – This is the final part of the if-statement, which is the path along which the program must flow if the expr is True.

This is just a recap of the if-statement in Python as the nested if is an extension of the same.

2. Nested If Statements

A nested if is an if statement that is the target of a previous if statement. Let us look at the syntax of a nested if-statement.

# Executes statement1 when expr1 is True # Executes statement2 when expr2 is True # Inner if-block ends here # Outer if-block ends here

Let us look at the flow chart of nested if-statement to have a better understanding of it: –

In the following example, we implement the nested if-statement on a program where the user inputs a number and checks different conditions with regards to that number. Though the program is very simple, the only intention is to discuss the nested if-statements’ flow.


a = 10 print("Inside initial if") print("Number is greater than 5") print("Inside first nested if") print("Number is greater than or equal to 10") print("Inside second nested if") print("Number is greater than or equal to 15") print("Outside second nested if") print("Outside second nested if") print("Outside initial if")

Output: –

The nested if must be properly indented, the failure of which results in Indentation Error as follows: –

a = 10 print("Greater than 7")

Output: –

Colon (:) must be follow all the ifs in the nested if-statements; otherwise, invalid syntax error would occur as follows:


a = 10 print("Greater than 7")



It is finally time to draw closure to this article. In this article, we learnt the need for Conditional Statements in programming, touched upon the basics of if-statement with its syntax. Lastly, we discussed about nested if-statements in Python in details. I hope by now you guys are able to appreciate the usage of nested if-statements in Python. Now it is time to write your own Python program implementing the concepts learnt in this article.

Recommended Articles

This is a guide to the Nested IF Statement in Python. Here we discuss the Nested IF Statement in Python detailed discussion with examples and its Code Implementation. You can also go through our other suggested articles to learn more –

Update the detailed information about Do While Loop In Python on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!