Simple Python Tutorial on "while" loop and introduce "break"

Publié le: 20 avril 2023
sur la chaîne: Earth Walker
147
6

Please like the video if it helps you :)

Simple python example and short video to illustrate how to construct a "while" loop and how it works. It starts by showing the various components of a "while" loop and how they are used to construct the loop. It then use a simple example to illustrate how a "while" loop functions. Using the same example, it introduces the "break" command and how it can be used to generate the same outcome. Instead of using a test condition to control whether to repeat, we can use a test condition to decide when to get out (exit) of the loop. Once the condition to exit the loop is True, we can use the "break" command to get out of the loop to execute the next statement after the "while" loop.

The construct of syntax of the "while" loop is
while (test condition):
indent == 1st command in the loop body
indent == ...
indent == last command in the loop body

The "break" command can be placed anywhere in the body of the loop to exit the loop. It depends on what you're trying to do.

You can also use the "break" command to break out of a "for" loop. Do note that if you have a nested loop (loop within a loop),
the "break" command will only exit the current loop that contain the "break" statement. It will be exit from all the other loops.

The example used is very simple just to illustrate the mechanics of a "while" loop so that hopefully it is easy for a beginner to understand.

You can use the link below to see some related videos
(Apart from watching the video, you can also show more info to read on the explanation.)
== how "while" loop works works ==
   • Simple Python Tutorial to introduce "while...  

== More on how "for" loop works ==
   • Simple Python Tutorial to introduce "for" ...  

Hope these inputs are helpful for you.

0:00 - Intro to "while" loop syntax and the components to setup
01:22 - Simple exaple to illsutrate a "while" loop running
03:29 - Amend to use "break" command to exit the loop and still having same outcome

Keywords:
#python
#while
#sentinel
#sentinelcontrol
#repeats
#loop
#loops
#break
#tutorial
#short
#simple
#easy


Sur cette page du site, vous pouvez voir la vidéo en ligne Simple Python Tutorial on "while" loop and introduce "break" durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Earth Walker 20 avril 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 147 fois et il a aimé 6 téléspectateurs. Bon visionnage!