question

Upvote
16 1 1 2

Regarding for Loop In Python

Hello All, I am new in this community. I am learning python and I want to know the difference between while loop, do while loop, and for loop? Can anyone tell me the difference with some basic examples with their syntax?

pythondata-fusion
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
9.6k 10 7 7

Hello @aartiyadavpersonal

This forum is aimed at software developers using Refinitiv APIs. The majority of the members of this forum and developers using Refinitiv APIs, the moderators on this forum are experts in the use of Refinitiv APIs.

For the programming language, coding questions like this one, you can post it on Stack Overflow Public Q&A which can help you get answers to your toughest coding questions.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 0 0 0

For Loop

The 'for' loop allows Initialization, Evaluation, and "Action" stages all placed within the loop declaration. It also supports locally scoped iterator & variables (memory efficiency, safety), something other types of loops such as the 'while' and 'do..while' loop doesn't. In the case of 'while' and 'do..while' loop, Initialization needs to be placed outside, only Evaluation is placed in loop declaration, and "Action" is placed inside the loop body.

While Loop

The 'while' loop evaluates loop condition BEFORE it executes the instructions inside the loop body, on the other hand...

Do While Loop

The 'do..while' loop evaluates loop condition AFTER it executes instructions inside the loop body (at least once). √ The 'do..while' loop is most suitable for situations where you need the loop to run once, at least, before the condition is evaluated. e.g. prompt for verifiable input, ask user login info, showing a menu, etc.

To know more and understand it deeper with the examples, Checkout this post.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.