Posts

Showing posts from July, 2020

Top 10 Programming Languages - 2020

Image
Credit:  IEEE Spectrum

Lesson 6 - Loops (While), Break, Continue

Hi, So today we learn loops. Many times we have some scenario where we need to repeat the steps. Here we come with solution called Loops. Python have "While" & "For" loop. While Loop While loop executed until the condition remains true. In while loop we initiate the variable that controls the counter for loop. Then apply the condition and inside the loop increment the counter by 1 or depends on your requirement. Example i = 1 while i <= 10:     print ("Do some coding")     i++ So first it check the conditions i <= 10 -> 1 <= 10 -> True -> Print -> Do some coding And so on until the condition is true. Above examples shows "Do some coding" 10 times. We can use below keywords inside loop to control the execution. 1. Break 2. Continue Break If our conditioned satisfied and we didn't need to execute the remaining we use break. It stops the execution and get the control out from loop. Continue We use "continue" ke...

Lesson 5 - Conditional Statements

Lesson 5 - Conditional Statements Hi All, I start the lesson with an example You need a drink but based on some condition like color, you ask shop keeper if you have white drink please give me 2 and if you don't have white give me any 1. So, in above example you use conditions. Similarly in programs we use condition to sort out the results. Another example is finding the grade based on your percentage. If percentage is between 90 - 100 your grade is A+ and so on. Syntax: The keyword 'if' is used for condition with conditional operators Example a = 20 b = 10 if a > b:     print("a is greater than b") Now you observe in above example if a is greater than b than it prints "a is greater than b" but if not than it didn't print anything. To handle this use case we use else if a > b:     print("a is greater than b") else:     print("a is not greater than b") For some cases we have multiple conditions to check for example do some ta...