Similar to any other kind of programming language, Python uses loops in order to iterate over the elements of a variable or an object. So in this lecture, I'm going to talk about loops, and their types, as well as giving some examples of loops. A loop is a sequence of instructions that is continuously repeated until a certain condition is met. So in this example, here, we have a collection of shapes, that is composed of squares and circles. And our iterator loops around these objects and takes out the circles leaving the squares intact. So this gets repeated over and over until all of the circles are taken out, and the squares are intact.
And then it stops. Another example is by writing a software code that can capitalize the letter T in a sentence. For instance, we have a variable called my text and it contains a sentence and we Want to capitalize the letter T in this sentence, which is this is a line of text to our iterator iterates over the string and converts all of the lowercase t into uppercase T. There are two main types of loops. The first one is wire loop and the other is for loop. The syntax of while loop starts with the word while then a condition to be met, and colon and then the second coming sentence is indented by four spaces. And then you write your statements, you would need to have at least one variable to be manipulated by the loop.
An example of wire loop is a simple Fibonacci series. A Fibonacci series is a series of numbers that increase in a certain fashion. So here, we introduce two variables here, x and y. So x is equal to zero and y to one Write down while y is smaller than and equal to hundred, colon print y. And then you write and equals to a space in a string format, then we did this every time the loop restarts, then we've run it, and we get the Fibonacci series for a series of numbers that are smaller than 100. The syntax of for loop is similar to this one, you have to have a variable that contains data, then you write down for each element in the variable, colon, then you write down the statements, but the statements should be indented.
You would need to note that the term each element is variable. So you can write any term or any word that each element term is the variable that has been created by the for loop. So for example, we have a text and we want to capitalized the letter T. And that text we write down for AI in txt, which is the variable that contains the text. If I is equal to lowercase t, print uppercase T, and it is shrink, else, print eye, so it's time it encounters the letter, lowercase t. It converts it to uppercase T. And then we execute this. We get the same sentence. However, all of the lowercase t have been converted to uppercase t