SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
>>> %Run -c $EDITOR_CONTENT
10
9
8
7
6
While Loop with Else
Like the
if
loop, the
while
loop can also have an optional
else
block.
If the condition in the
while
loop is evaluated as
False
, the
else
part is executed.
x
=
10
while
x
>
0
:
(x)
x
-=
1
else
:
(
"Game Over"
)
>>> %Run -c $EDITOR_CONTENT
10
9
8
7
6
5
4
3
2
1
Game Over
3.5.7 For Loops
The
for
loop can traverse any sequence of items, such as a list or a string.
The syntax format of for loop is as follows:
for
val
in
sequence:
Body of
for
Here,
val
is a variable that gets the value of the item in the sequence in each iteration.
The loop continues until we reach the last item in the sequence. Use indentation to separate the body of the
for
loop
from the rest of the code.
Flowchart of for Loop
118
Chapter 3. For MicroPython User
Summary of Contents for Thales Kit
Page 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Page 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Page 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...