• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/3

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

3 Cards in this Set

  • Front
  • Back

while-loop

A while-loop will keep executing the code block under it as long as a boolean expression is true.



while-loops. What they do is simply do a test like anif-statement, but instead of running the code block once, they jump back to the "top" where the while is, and repeat. Awhile-loop runs until the expression is false.



warning with while loops: Sometimes they do not stop. You almost always want your loops to end eventually. To avoid these issues:


1) Make sure that you use while-loops sparingly. Usually a for-loop is better.


2) Review your while statements and make sure that the boolean test will become false at some point.


3) When in doubt, print out your test variable at the top and bottom of the while-loop to see what it's doing.

for-loop

A for-loop can only iterate (loop) "over" collections of things.

if-statements

Rules:


1) every if-statement must have an else.


2) if this else should never run, because it doesn't make sense, then you must use a die function in the else that prints out an error message and dies, just like we did in the last exercise. This will find many errors.


3) Never nest if-statements more than two deep and always try to do them one deep.


4) Treat if-statements like paragraphs, where each if-elsif-else grouping is like a set of sentences. Put blank lines before and after.


5) Your boolean tests should be simple. If they are complex, move their calculations to variables earlier in your function and use a good name for the variable.