YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← One Thing or Nothing At All - Intro to Java Programming

Get Embed Code
6 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. There are a couple of other odds and ends
  2. about the if statement that I want to briefly talk
  3. about. So you know now that the if statement
  4. makes a decision. You go one way or another, depending
  5. on some condition. Now, sometimes, you're code is arranged
  6. so that you don't actually have a decision to do
  7. one thing or another, but the decision is between
  8. one thing and nothing at all. For example, over here,
  9. I've rearranged the code for computing the actual floor a
  10. bit. I'm initializing actual flow with the floor and then
  11. I only need to adjust it if the floor is
  12. greater than 13 and otherwise I need do nothing at
  13. all. In this case, it is perfectly legal to omit
  14. the else part. That's like if you only choose between
  15. doing something or just staying in place. It's okay to
  16. do more than one thing. You could put other actions
  17. inside here, maybe a print statement. Generally in more
  18. complicated situations, there's going to be several statements in between the
  19. braces. Conversely, if there is only one action here, it's
  20. legal to omit the braces. But we won't ever do
  21. that, it's just clear to always put them there.
  22. Makes the code easier to read. Now go ahead and
  23. work out a couple more practice problems with Sarah. And
  24. then we'll talk more about how these conditions are formed.