From dbb9bcbef8be3e7202b638ae163772e28bbcbb92 Mon Sep 17 00:00:00 2001 From: Vaibhav Malaviya <55515799+vaimalaviya1233@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:31:57 -0500 Subject: [PATCH] Create index.md for python loops --- docs/snippets/python/loops/index.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 docs/snippets/python/loops/index.md diff --git a/docs/snippets/python/loops/index.md b/docs/snippets/python/loops/index.md new file mode 100644 index 0000000..44daa4d --- /dev/null +++ b/docs/snippets/python/loops/index.md @@ -0,0 +1,29 @@ +--- +title: Python Loops +titleTemplate: Snippet Collection | massCode +description: Collection of Python Loop snippets +--- + +# Python Loops + +## Loops +Genarally speaking python only has 2 types of loops, even though if...else comes in conditional statements I have included it in this section. +Loops are one of basic in python however it comes handy when you want to perform operation again repeatedly. +for and while loops are mostly used more. + + +***you can also insert "pass" key word instead of statements which you don't want to execute thus it skips executing that block of code in loops*** + +however if you comes from other language background such as C++ or java, Python does not have do-while loop. but i'm sure our brilliant minds will make your self some crazy idea just for do-while loop. :) + +### While Loop +_Tip :- you can use else with while loops thus you can create do-while loop however it acts as postcondition loop such that condition is tested first before any statements in while true or else block statements are executed._ + +#### Syntax of while loop +```python +while conditional_test: + statement_to_execute_when_conditinal_test_is_true +else: + else_statement_when_conditinal_test_is_false +``` +