Loops in Python



As is usual in almost all programming languages, so-called loops exist in the programming language Python. They are part of a modern programming language and will follow us in the next topics why we would like to go into the topic area exactly.

The Java2Enterprise team mainly uses the programming languages Java, Python and C #. In
addition, we use the programming language R for mathematical or statistical
calculations, which derives from the programming language S.


In the most common programming languages, there are loops such as the for loop, while loop, do-while loop. The language C # has a sleeve in the ace, because it has four loop types. The
fourth is the so-called foreach loop.
We have a
much easier time with Python programming because we only use the For loop, also
called the enumeration loop, and the while loop, the so-called
condition-checking loop.


Let´s start with a simple example.

We will program an enumerative loop and use a module that contains the name "range ()". Of course, this module includes values that programmers should enter before running the program. At least two values, one the start value and the end value, should be entered. Of course
you can enter the increment as the third parameter.
If the programmer has only entered two values, the step size is therefore one.




The first for loop starts counting from one to four. The final value 5 is not output here. In this case, the run variable is "i".

The second for loop starts counting from one to five. As in the first loop, the final value will not be output here.

The third For loop looks identical to the other two except for one parameter. The third
loop also contains the step size.
For the
first and second loops, the step size was one.
Here it
is the two.


The output oft he three loops looks like this:




Of course, in Python, besides the for loop, there is the so-called while loop. The while
loop is, as mentioned above, a conditional loop.
This
means that a condition must be fulfilled for the start of the loop in order to
execute this.




A while loop in Python has the following build:




Let's first
look at the code between lines 12 through 27. How do the variables a and b
initialize with Mathematical Values. The first
loop is then executed because the condition matches.
The first loop counts down from ten to
zero in increments of one.



The second loop does
exactly the opposite of the first loop.
This
lists the values and outputs them each time.
You can
find the codes >> HERE <<

Kommentare

Beliebte Posts aus diesem Blog

How can I transform a .jar file to a .bat file?

Raspberry Pi als echten Web- und Mailserver einsetzen (German)

Umrechnung von Grad Celsius nach Grad Fahrenheit