term1 Definition1term2 Definition2term3 Definition3
Please sign in to your Google account to access your documents:
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.
Need help typing ? See our FAQ (opens in new window)
Please sign in to create this set. We'll bring you back here when you are done.
Discard Changes Sign in
Please sign in to add to folders.
Sign in
Don't have an account? Sign Up »
You have created 2 folders. Please upgrade to Cram Premium to create hundreds of folders!