From a15f2e71816fbae01bf88981e51cbfeeb4557389 Mon Sep 17 00:00:00 2001 From: Anushan Santhirakumar <73377435+Anushan1508@users.noreply.github.com> Date: Sat, 23 Oct 2021 14:05:28 +0530 Subject: [PATCH 1/8] Create while.py --- Python/Loops/while.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Python/Loops/while.py diff --git a/Python/Loops/while.py b/Python/Loops/while.py new file mode 100644 index 0000000..dd94329 --- /dev/null +++ b/Python/Loops/while.py @@ -0,0 +1,11 @@ +#With the while loop we can execute a set of statements as long as a condition is true. + + +i = 1 +while i < 6: + print(i) + i += 1 + + #This is basic while loop. It will print 1 to 6 numbers using While loop. There is an condition like i<6. SO it loop will be run untill i<6. Every while excution i will increase by 1. + #remember to increment i, or else the loop will continue forever. + #The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1. From b9df1f67bb656162403e4740bfba427b958f5e43 Mon Sep 17 00:00:00 2001 From: Anushan Santhirakumar <73377435+Anushan1508@users.noreply.github.com> Date: Sat, 23 Oct 2021 14:10:28 +0530 Subject: [PATCH 2/8] Create for.py --- Python/Loops/for.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Python/Loops/for.py diff --git a/Python/Loops/for.py b/Python/Loops/for.py new file mode 100644 index 0000000..780eb14 --- /dev/null +++ b/Python/Loops/for.py @@ -0,0 +1,10 @@ +#A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). +#This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages. +#With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc. + +fruits = ["apple", "banana", "cherry"] +for x in fruits: + print(x) + + +#The for loop does not require an indexing variable to set beforehand. From e72033cbac2a35f8df6c7f00fdc0f5b7a7a1a1dd Mon Sep 17 00:00:00 2001 From: Anushan Santhirakumar <73377435+Anushan1508@users.noreply.github.com> Date: Sat, 23 Oct 2021 18:11:09 +0530 Subject: [PATCH 3/8] Create while.ipynb --- Python/Loops/while.ipynb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Python/Loops/while.ipynb diff --git a/Python/Loops/while.ipynb b/Python/Loops/while.ipynb new file mode 100644 index 0000000..766e4b5 --- /dev/null +++ b/Python/Loops/while.ipynb @@ -0,0 +1,11 @@ +//With the while loop we can execute a set of statements as long as a condition is true. + + +i = 1 +while i < 6: + print(i) + i += 1 + + //This is basic while loop. It will print 1 to 6 numbers using While loop. There is an condition like i<6. SO it loop will be run untill i<6. Every while excution i will increase by 1. + //remember to increment i, or else the loop will continue forever. + //The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1. From bf419b13a773e0f948db8f43970e65dfc93efdf7 Mon Sep 17 00:00:00 2001 From: Anushan Santhirakumar <73377435+Anushan1508@users.noreply.github.com> Date: Sat, 23 Oct 2021 18:11:23 +0530 Subject: [PATCH 4/8] Delete while.py --- Python/Loops/while.py | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 Python/Loops/while.py diff --git a/Python/Loops/while.py b/Python/Loops/while.py deleted file mode 100644 index dd94329..0000000 --- a/Python/Loops/while.py +++ /dev/null @@ -1,11 +0,0 @@ -#With the while loop we can execute a set of statements as long as a condition is true. - - -i = 1 -while i < 6: - print(i) - i += 1 - - #This is basic while loop. It will print 1 to 6 numbers using While loop. There is an condition like i<6. SO it loop will be run untill i<6. Every while excution i will increase by 1. - #remember to increment i, or else the loop will continue forever. - #The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1. From 287386bb44a682ebd8fa6b90686bab252d966fc5 Mon Sep 17 00:00:00 2001 From: Anushan Santhirakumar <73377435+Anushan1508@users.noreply.github.com> Date: Sat, 23 Oct 2021 18:12:08 +0530 Subject: [PATCH 5/8] Delete for.py --- Python/Loops/for.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 Python/Loops/for.py diff --git a/Python/Loops/for.py b/Python/Loops/for.py deleted file mode 100644 index 780eb14..0000000 --- a/Python/Loops/for.py +++ /dev/null @@ -1,10 +0,0 @@ -#A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). -#This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages. -#With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc. - -fruits = ["apple", "banana", "cherry"] -for x in fruits: - print(x) - - -#The for loop does not require an indexing variable to set beforehand. From 99433c63295668743e9dd2faa5fa6b11ded7d90c Mon Sep 17 00:00:00 2001 From: Anushan Santhirakumar <73377435+Anushan1508@users.noreply.github.com> Date: Sat, 23 Oct 2021 23:17:55 +0530 Subject: [PATCH 6/8] Update while.ipynb --- Python/Loops/while.ipynb | 62 ++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/Python/Loops/while.ipynb b/Python/Loops/while.ipynb index 766e4b5..acf3c5b 100644 --- a/Python/Loops/while.ipynb +++ b/Python/Loops/while.ipynb @@ -1,11 +1,57 @@ -//With the while loop we can execute a set of statements as long as a condition is true. +/* + Q1. What is While Loop? + Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied +*/ +/* +Syntax of while Loop in Python + +while test_expression: + Body of while +*/ + +//Examples - 01 + +// Program to add natural +// numbers up to +// sum = 1+2+3+...+n + +// To take input from the user, +// n = int(input("Enter n: ")) + +n = 10 + +// initialize sum and counter +sum = 0 i = 1 -while i < 6: - print(i) - i += 1 - - //This is basic while loop. It will print 1 to 6 numbers using While loop. There is an condition like i<6. SO it loop will be run untill i<6. Every while excution i will increase by 1. - //remember to increment i, or else the loop will continue forever. - //The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1. + +while i <= n: + sum = sum + i + i = i+1 # update counter + +// print the sum +print("The sum is", sum) + +//Output - 01 +/* +Enter n: 10 +The sum is 55 +*/ + +// Example - 02 +counter = 0 + +while counter < 3: + print("Inside loop") + counter = counter + 1 +else: + print("Inside else") + +//Output - 02 +/* +Inside loop +Inside loop +Inside loop +Inside else +*/ From 600067cebff2f5379599aae5c461bc860212cc5e Mon Sep 17 00:00:00 2001 From: Anushan Santhirakumar <73377435+Anushan1508@users.noreply.github.com> Date: Sat, 23 Oct 2021 23:50:47 +0530 Subject: [PATCH 7/8] Delete while.ipynb --- Python/Loops/while.ipynb | 57 ---------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 Python/Loops/while.ipynb diff --git a/Python/Loops/while.ipynb b/Python/Loops/while.ipynb deleted file mode 100644 index acf3c5b..0000000 --- a/Python/Loops/while.ipynb +++ /dev/null @@ -1,57 +0,0 @@ -/* - Q1. What is While Loop? - Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied -*/ - - -/* -Syntax of while Loop in Python - -while test_expression: - Body of while -*/ - -//Examples - 01 - -// Program to add natural -// numbers up to -// sum = 1+2+3+...+n - -// To take input from the user, -// n = int(input("Enter n: ")) - -n = 10 - -// initialize sum and counter -sum = 0 -i = 1 - -while i <= n: - sum = sum + i - i = i+1 # update counter - -// print the sum -print("The sum is", sum) - -//Output - 01 -/* -Enter n: 10 -The sum is 55 -*/ - -// Example - 02 -counter = 0 - -while counter < 3: - print("Inside loop") - counter = counter + 1 -else: - print("Inside else") - -//Output - 02 -/* -Inside loop -Inside loop -Inside loop -Inside else -*/ From 8fb1f94c2c4da11e9b731f1180dccc415b7eb324 Mon Sep 17 00:00:00 2001 From: Anushan Santhirakumar <73377435+Anushan1508@users.noreply.github.com> Date: Sat, 23 Oct 2021 23:51:06 +0530 Subject: [PATCH 8/8] Create whileNew.ipynb --- Python/Loops/whileNew.ipynb | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Python/Loops/whileNew.ipynb diff --git a/Python/Loops/whileNew.ipynb b/Python/Loops/whileNew.ipynb new file mode 100644 index 0000000..acf3c5b --- /dev/null +++ b/Python/Loops/whileNew.ipynb @@ -0,0 +1,57 @@ +/* + Q1. What is While Loop? + Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied +*/ + + +/* +Syntax of while Loop in Python + +while test_expression: + Body of while +*/ + +//Examples - 01 + +// Program to add natural +// numbers up to +// sum = 1+2+3+...+n + +// To take input from the user, +// n = int(input("Enter n: ")) + +n = 10 + +// initialize sum and counter +sum = 0 +i = 1 + +while i <= n: + sum = sum + i + i = i+1 # update counter + +// print the sum +print("The sum is", sum) + +//Output - 01 +/* +Enter n: 10 +The sum is 55 +*/ + +// Example - 02 +counter = 0 + +while counter < 3: + print("Inside loop") + counter = counter + 1 +else: + print("Inside else") + +//Output - 02 +/* +Inside loop +Inside loop +Inside loop +Inside else +*/