Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 322984e

Browse files
Break, continue and pass
1 parent 1bed201 commit 322984e

File tree

2 files changed

+110
-4
lines changed

2 files changed

+110
-4
lines changed

‎2. Flow_control/.ipynb_checkpoints/4. Break_and_Continue-checkpoint.ipynb‎ renamed to ‎2. Flow_control/.ipynb_checkpoints/4. Break_Continue_and_Pass-checkpoint.ipynb‎

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"## 1. Breakand Continue\n",
7+
"## 1. Break, continue and pass statements\n",
88
"In Python, `break` and `continue` statements can alter the flow of a normal loop.<br>\n",
99
"`Break` - exits the loop completely.<br>\n",
10-
"`Continue` - exits the current iteration of the loop and continues with the next iteration."
10+
"`Continue` - exits the current iteration of the loop and continues with the next iteration.<br>\n",
11+
"`Pass` - pass is a null statement. Nothing happens when the pass is executed. It results in no operation (NOP)."
1112
]
1213
},
1314
{
@@ -158,6 +159,58 @@
158159
"We continue with the loop, if the string is i, not executing the rest of the block. Hence, we see in our output that all the letters except i gets printed."
159160
]
160161
},
162+
{
163+
"cell_type": "markdown",
164+
"metadata": {},
165+
"source": [
166+
"## 4. Pass statement\n",
167+
"In Python, `pass` is a null statement. <br>\n",
168+
"The difference between a [comment](https://www.programiz.com/python-programming/statement-indentation-comments) and a `pass` statement in Python is that while the interpreter ignores a comment entirely, `pass` is not ignored.\n",
169+
"\n",
170+
"However, nothing happens when the pass is executed. It results in no operation (NOP)."
171+
]
172+
},
173+
{
174+
"cell_type": "markdown",
175+
"metadata": {},
176+
"source": [
177+
"**Syntax of pass statement**<br>\n",
178+
"Suppose we have a loop or a function that is not implemented yet, but we want to implement it in the future. <br>They cannot have an empty body. The interpreter would give an error. So, we use the `pass` statement to construct a body that does nothing."
179+
]
180+
},
181+
{
182+
"cell_type": "code",
183+
"execution_count": 6,
184+
"metadata": {},
185+
"outputs": [],
186+
"source": [
187+
"'''pass is just a placeholder for\n",
188+
"functionality to be added later.'''\n",
189+
"sequence = {'p', 'a', 's', 's'}\n",
190+
"for val in sequence:\n",
191+
" pass"
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": 8,
197+
"metadata": {},
198+
"outputs": [],
199+
"source": [
200+
"def function(args):\n",
201+
" pass"
202+
]
203+
},
204+
{
205+
"cell_type": "code",
206+
"execution_count": 9,
207+
"metadata": {},
208+
"outputs": [],
209+
"source": [
210+
"class Example:\n",
211+
" pass"
212+
]
213+
},
161214
{
162215
"cell_type": "code",
163216
"execution_count": null,

‎2. Flow_control/4. Break_and_Continue.ipynb‎ renamed to ‎2. Flow_control/4. Break_Continue_and_Pass.ipynb‎

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"## 1. Breakand Continue\n",
7+
"## 1. Break, continue and pass statements\n",
88
"In Python, `break` and `continue` statements can alter the flow of a normal loop.<br>\n",
99
"`Break` - exits the loop completely.<br>\n",
10-
"`Continue` - exits the current iteration of the loop and continues with the next iteration."
10+
"`Continue` - exits the current iteration of the loop and continues with the next iteration.<br>\n",
11+
"`Pass` - pass is a null statement. Nothing happens when the pass is executed. It results in no operation (NOP)."
1112
]
1213
},
1314
{
@@ -158,6 +159,58 @@
158159
"We continue with the loop, if the string is i, not executing the rest of the block. Hence, we see in our output that all the letters except i gets printed."
159160
]
160161
},
162+
{
163+
"cell_type": "markdown",
164+
"metadata": {},
165+
"source": [
166+
"## 4. Pass statement\n",
167+
"In Python, `pass` is a null statement. <br>\n",
168+
"The difference between a [comment](https://www.programiz.com/python-programming/statement-indentation-comments) and a `pass` statement in Python is that while the interpreter ignores a comment entirely, `pass` is not ignored.\n",
169+
"\n",
170+
"However, nothing happens when the pass is executed. It results in no operation (NOP)."
171+
]
172+
},
173+
{
174+
"cell_type": "markdown",
175+
"metadata": {},
176+
"source": [
177+
"**Syntax of pass statement**<br>\n",
178+
"Suppose we have a loop or a function that is not implemented yet, but we want to implement it in the future. <br>They cannot have an empty body. The interpreter would give an error. So, we use the `pass` statement to construct a body that does nothing."
179+
]
180+
},
181+
{
182+
"cell_type": "code",
183+
"execution_count": 6,
184+
"metadata": {},
185+
"outputs": [],
186+
"source": [
187+
"'''pass is just a placeholder for\n",
188+
"functionality to be added later.'''\n",
189+
"sequence = {'p', 'a', 's', 's'}\n",
190+
"for val in sequence:\n",
191+
" pass"
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": 8,
197+
"metadata": {},
198+
"outputs": [],
199+
"source": [
200+
"def function(args):\n",
201+
" pass"
202+
]
203+
},
204+
{
205+
"cell_type": "code",
206+
"execution_count": 9,
207+
"metadata": {},
208+
"outputs": [],
209+
"source": [
210+
"class Example:\n",
211+
" pass"
212+
]
213+
},
161214
{
162215
"cell_type": "code",
163216
"execution_count": null,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /