1+ {
2+ "nbformat" : 4 ,
3+ "nbformat_minor" : 0 ,
4+ "metadata" : {
5+ "colab" : {
6+ "provenance" : [],
7+ "authorship_tag" : " ABX9TyNL+KXQvNjtdKtxa4gjCR8R" ,
8+ "include_colab_link" : true
9+ },
10+ "kernelspec" : {
11+ "name" : " python3" ,
12+ "display_name" : " Python 3"
13+ },
14+ "language_info" : {
15+ "name" : " python"
16+ }
17+ },
18+ "cells" : [
19+ {
20+ "cell_type" : " markdown" ,
21+ "metadata" : {
22+ "id" : " view-in-github" ,
23+ "colab_type" : " text"
24+ },
25+ "source" : [
26+ " <a href=\" https://colab.research.google.com/github/ambilisunil/python_basics/blob/main/loops.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
27+ ]
28+ },
29+ {
30+ "cell_type" : " markdown" ,
31+ "source" : [
32+ " # **WHILE LOOP**"
33+ ],
34+ "metadata" : {
35+ "id" : " M_YuUybyTmF6"
36+ }
37+ },
38+ {
39+ "cell_type" : " code" ,
40+ "execution_count" : 2 ,
41+ "metadata" : {
42+ "colab" : {
43+ "base_uri" : " https://localhost:8080/"
44+ },
45+ "id" : " sBlc7oPTSpfT" ,
46+ "outputId" : " dd338845-f61c-45c9-d926-31c0982525aa"
47+ },
48+ "outputs" : [
49+ {
50+ "output_type" : " stream" ,
51+ "name" : " stdout" ,
52+ "text" : [
53+ " 0\n " ,
54+ " 1\n " ,
55+ " 2\n " ,
56+ " 3\n " ,
57+ " 4\n " ,
58+ " 5\n " ,
59+ " 6\n " ,
60+ " 7\n " ,
61+ " 8\n " ,
62+ " 9\n " ,
63+ " 10\n " ,
64+ " i<== 10 i=== 11\n "
65+ ]
66+ }
67+ ],
68+ "source" : [
69+ " n=10\n " ,
70+ " i=0\n " ,
71+ " while(i<=n):\n " ,
72+ " print(i)\n " ,
73+ " i=i+1\n " ,
74+ " else:\n " ,
75+ " print(\" i<==\" ,n,\" i=== \" ,i)"
76+ ]
77+ },
78+ {
79+ "cell_type" : " markdown" ,
80+ "source" : [
81+ " # **FOR LOOP**"
82+ ],
83+ "metadata" : {
84+ "id" : " VyTz5_dWTwW_"
85+ }
86+ },
87+ {
88+ "cell_type" : " markdown" ,
89+ "source" : [
90+ " **RANGE**"
91+ ],
92+ "metadata" : {
93+ "id" : " 4yAiaYl9UDrg"
94+ }
95+ },
96+ {
97+ "cell_type" : " code" ,
98+ "source" : [
99+ " a=list(range(10))\n " ,
100+ " print(a)"
101+ ],
102+ "metadata" : {
103+ "colab" : {
104+ "base_uri" : " https://localhost:8080/"
105+ },
106+ "id" : " xVR6LLUPUHX7" ,
107+ "outputId" : " 550867ca-1696-4511-8124-55826a4f2e1a"
108+ },
109+ "execution_count" : 4 ,
110+ "outputs" : [
111+ {
112+ "output_type" : " stream" ,
113+ "name" : " stdout" ,
114+ "text" : [
115+ " [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n "
116+ ]
117+ }
118+ ]
119+ },
120+ {
121+ "cell_type" : " code" ,
122+ "source" : [
123+ " a=list(range(2,10))\n " ,
124+ " print(a)\n "
125+ ],
126+ "metadata" : {
127+ "colab" : {
128+ "base_uri" : " https://localhost:8080/"
129+ },
130+ "id" : " E72HCUj6UQtP" ,
131+ "outputId" : " 70398161-54a3-453d-f7d5-5741489549f8"
132+ },
133+ "execution_count" : 7 ,
134+ "outputs" : [
135+ {
136+ "output_type" : " stream" ,
137+ "name" : " stdout" ,
138+ "text" : [
139+ " [2, 3, 4, 5, 6, 7, 8, 9]\n "
140+ ]
141+ }
142+ ]
143+ },
144+ {
145+ "cell_type" : " code" ,
146+ "source" : [
147+ " a=list(range(2,10,2))\n " ,
148+ " print(a)"
149+ ],
150+ "metadata" : {
151+ "colab" : {
152+ "base_uri" : " https://localhost:8080/"
153+ },
154+ "id" : " LnFtz_yJUeQF" ,
155+ "outputId" : " 5e2e6ff2-c7d3-4cff-a31f-c24c04cbddd6"
156+ },
157+ "execution_count" : 8 ,
158+ "outputs" : [
159+ {
160+ "output_type" : " stream" ,
161+ "name" : " stdout" ,
162+ "text" : [
163+ " [2, 4, 6, 8]\n "
164+ ]
165+ }
166+ ]
167+ },
168+ {
169+ "cell_type" : " markdown" ,
170+ "source" : [
171+ " for loop **in**"
172+ ],
173+ "metadata" : {
174+ "id" : " mALKWN1JVJS8"
175+ }
176+ },
177+ {
178+ "cell_type" : " code" ,
179+ "source" : [
180+ " for i in a :\n " ,
181+ " print(i)"
182+ ],
183+ "metadata" : {
184+ "colab" : {
185+ "base_uri" : " https://localhost:8080/"
186+ },
187+ "id" : " SHpRNvxXUuE4" ,
188+ "outputId" : " 70ba312c-d0ef-4c07-a602-61646dc7e674"
189+ },
190+ "execution_count" : 13 ,
191+ "outputs" : [
192+ {
193+ "output_type" : " stream" ,
194+ "name" : " stdout" ,
195+ "text" : [
196+ " 2\n " ,
197+ " 4\n " ,
198+ " 6\n " ,
199+ " 8\n "
200+ ]
201+ }
202+ ]
203+ },
204+ {
205+ "cell_type" : " code" ,
206+ "source" : [
207+ " for i in range(10): # for=> for(i=0;<10;i++)\n " ,
208+ " print(i,end=\"\" ) # end useualy /n new line, replace end line with space"
209+ ],
210+ "metadata" : {
211+ "colab" : {
212+ "base_uri" : " https://localhost:8080/"
213+ },
214+ "id" : " Z9itKI92VYKI" ,
215+ "outputId" : " 5d5320e6-c2b9-47d0-8061-cc7a58283c7d"
216+ },
217+ "execution_count" : 14 ,
218+ "outputs" : [
219+ {
220+ "output_type" : " stream" ,
221+ "name" : " stdout" ,
222+ "text" : [
223+ " 0123456789"
224+ ]
225+ }
226+ ]
227+ }
228+ ]
229+ }
0 commit comments