You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"# Let us now look at a sample program in Python to demonstrate the For statement.\n",
89
+
"\n",
90
+
"travelling = input(\"Are you travelling? Yes or No:\")\n",
91
+
"while travelling == 'yes':\n",
92
+
" num = int(input(\"Enter the number of people travelling:\"))\n",
93
+
" for num in range(1,num+1):\n",
94
+
" name = input(\"Enter Details Name:\")\n",
95
+
" age = input(\"Age:\")\n",
96
+
" sex = input(\"Male or Female:\")\n",
97
+
" print(\"Details Stored\",name)\n",
98
+
" print(age)\n",
99
+
" print(sex)\n",
100
+
" print(\"Thank you!\")\n",
101
+
" travelling = input(\"Are you travelling? Yes or No:\")\n",
102
+
"print(\"Please come back again.\")"
103
+
],
104
+
"execution_count": 7,
105
+
"outputs": [
106
+
{
107
+
"output_type": "stream",
108
+
"text": [
109
+
"Are you travelling? Yes or No:yes\n",
110
+
"Enter the number of people travelling:1\n",
111
+
"Enter Details Name:Suneel Patel\n",
112
+
"Age:33\n",
113
+
"Male or Female:Male\n",
114
+
"Details Stored Suneel Patel\n",
115
+
"33\n",
116
+
"Male\n",
117
+
"Thank you!\n",
118
+
"Are you travelling? Yes or No:no\n",
119
+
"Please come back again.\n"
120
+
],
121
+
"name": "stdout"
122
+
}
123
+
]
124
+
},
125
+
{
126
+
"cell_type": "markdown",
127
+
"metadata": {
128
+
"id": "jz3HnD2MM6r8",
129
+
"colab_type": "text"
130
+
},
131
+
"source": [
132
+
"## While Statement: \n",
133
+
"\n",
134
+
"---\n",
135
+
"\n",
136
+
"The while statement in Python programming supports repeated execution of a statement or block of statements that is controlled by a conditional expression."
"# Let us now look at a sample program in Python to demonstrate the While statement.\n",
152
+
"count = 0\n",
153
+
"print('Printing numbers from 0 to 9')\n",
154
+
"while (count<10):\n",
155
+
" print('The count is ',count)\n",
156
+
" count = count+1\n",
157
+
"print('Good Bye')\n"
158
+
],
159
+
"execution_count": 13,
160
+
"outputs": [
161
+
{
162
+
"output_type": "stream",
163
+
"text": [
164
+
"Printing numbers from 0 to 9\n",
165
+
"The count is 0\n",
166
+
"The count is 1\n",
167
+
"The count is 2\n",
168
+
"The count is 3\n",
169
+
"The count is 4\n",
170
+
"The count is 5\n",
171
+
"The count is 6\n",
172
+
"The count is 7\n",
173
+
"The count is 8\n",
174
+
"The count is 9\n",
175
+
"Good Bye\n"
176
+
],
177
+
"name": "stdout"
178
+
}
179
+
]
180
+
},
181
+
{
182
+
"cell_type": "markdown",
183
+
"metadata": {
184
+
"id": "GycaNZgCNO22",
185
+
"colab_type": "text"
186
+
},
187
+
"source": [
188
+
"## Break Statement: \n",
189
+
"\n",
190
+
"---\n",
191
+
"The break statement is allowed only inside a loop body. When break executes, the loop terminates. If a loop is nested inside other loops, break terminates only the innermost nested loop."
"for letter in 'The Quick Brown Fox. Jumps, Over The Lazy Dog':\n",
207
+
" if letter == '.':\n",
208
+
" break\n",
209
+
" print ('Current Letter :', letter)"
210
+
],
211
+
"execution_count": 14,
212
+
"outputs": [
213
+
{
214
+
"output_type": "stream",
215
+
"text": [
216
+
"Current Letter : T\n",
217
+
"Current Letter : h\n",
218
+
"Current Letter : e\n",
219
+
"Current Letter : \n",
220
+
"Current Letter : Q\n",
221
+
"Current Letter : u\n",
222
+
"Current Letter : i\n",
223
+
"Current Letter : c\n",
224
+
"Current Letter : k\n",
225
+
"Current Letter : \n",
226
+
"Current Letter : B\n",
227
+
"Current Letter : r\n",
228
+
"Current Letter : o\n",
229
+
"Current Letter : w\n",
230
+
"Current Letter : n\n",
231
+
"Current Letter : \n",
232
+
"Current Letter : F\n",
233
+
"Current Letter : o\n",
234
+
"Current Letter : x\n"
235
+
],
236
+
"name": "stdout"
237
+
}
238
+
]
239
+
},
240
+
{
241
+
"cell_type": "markdown",
242
+
"metadata": {
243
+
"id": "nYBMT0opNii0",
244
+
"colab_type": "text"
245
+
},
246
+
"source": [
247
+
"## Continue Statement: \n",
248
+
"\n",
249
+
"---\n",
250
+
"\n",
251
+
"The continue statement is allowed only inside a loop body. When continue executes, the current iteration of the loop body terminates, and execution continues with the next iteration of the loop."
"# Let us now look at a sample program in Python to demonstrate the Continue statement.\n",
267
+
"for num in range(10, 21):\n",
268
+
" if num % 5 == 0:\n",
269
+
" print (\"Found a multiple of 5\")\n",
270
+
" pass\n",
271
+
" num = num + 1\n",
272
+
" continue\n",
273
+
" print (\"Found number: \", num)"
274
+
],
275
+
"execution_count": 15,
276
+
"outputs": [
277
+
{
278
+
"output_type": "stream",
279
+
"text": [
280
+
"Found a multiple of 5\n",
281
+
"Found number: 11\n",
282
+
"Found number: 12\n",
283
+
"Found number: 13\n",
284
+
"Found number: 14\n",
285
+
"Found a multiple of 5\n",
286
+
"Found number: 16\n",
287
+
"Found number: 17\n",
288
+
"Found number: 18\n",
289
+
"Found number: 19\n",
290
+
"Found a multiple of 5\n"
291
+
],
292
+
"name": "stdout"
293
+
}
294
+
]
295
+
},
296
+
{
297
+
"cell_type": "markdown",
298
+
"metadata": {
299
+
"id": "E-0VnJwjOCnM",
300
+
"colab_type": "text"
301
+
},
302
+
"source": [
303
+
"## Pass Statement:\n",
304
+
"\n",
305
+
"---\n",
306
+
"\n",
307
+
"The pass statement, which performs no action, can be used as a placeholder when a statement is syntactically required but you have nothing specific to do."
0 commit comments