previousGradeNum
also is greater than 90. This question will only get asked
if
gradeNum
is greater than 90. The in denting helps to see the nesting. It is partic-
ularly help ful if the nested
If
block is more com plicated, with its own
Else
, for
ex am ple. The
Else
should always be lined up with the
If
with which it goes.
The
If
statement is very pow erful. It is one of the things that al lows for in -
teraction. Without con ditional statements, every user would do ex actly the same
thing as the previous user.
Loop ing
If
statements allow you to make choices based on whether or not a condi-
tion is true. Loop ing al lows you to do something over and over again. How many
times is based on a con dition, that is, a question like what you ask in an
If
state -
ment. This is known as the stop ping con dition. In some types of loops (such as a
While
loop), this question is phrased as a keep go ing ques tion, and in other
types of loops (such as a
For Next
loop), the con dition is based on how many
times you say you want to loop. However the question is phrased, the loop needs
to know when to stop.
While
Loops
There are sev eral types of loops, and you might want to ex plore different
ones, but once you know one, you can do just about any thing you might want to
do. Let’s look at the
While
loop. The
While
loop asks a question and keeps loop-
ing while the answer to the ques tion is yes. My four-year-old daugh ter might ask
“Is it still raining?” She might ask this over and over again un til it has stopped rain-
ing. As long as it is rain ing, she will add an other block to her tower and ask again:
Do'stlaringiz bilan baham: |