userName
).
done
is de clared as
Boolean
be cause
Boolean
variables can be
True
or
False
, and we are ei ther
done or we are not done.
We start by setting the value of
done
to
False
(be cause the stu dent surely
has not typed a name before we even have asked). Next, we use a
While
loop
(see Chapter 8 for more about
While
loops). This is a method of do ing some-
thing over and over again as long as we want to keep go ing. We know we want to
keep go ing if whatever co mes af ter the word
While
is
True
.
Not False
is the
same thing as
True
, so if
done
is
False
,
Not done
is
True
, and we keep go -
ing. In Eng lish, we keep go ing as long as we are not done.
How do we know when we are done? That is where the
If
state ment co mes
in. We check to see what the student has typed (as stored in
userName
) and
compare that to
""
(that is two dou ble quotes with noth ing be tween them, also
known as the empty string or nothing). If the student typed noth
ing (
If
username = "" Then
) then we are not done, so we set
done
to
False
(
done
= False
); that is, we put the value
False
in the vari able named
done
. Oth er-
wise (
Else
) the student must have typed something, so we are done, and we set
56 Let’s Get Scripting
done
to
Do'stlaringiz bilan baham: |