CrashCourse · @crashcourse

Programming Basics: Statements & Functions: Crash Course Computer Science #12

Uploaded June 8, 2017 · Length 11:57

Programming Basics: Statements & Functions: Crash Course Computer Science #12

Summary

Learn about programming statements, assignment, syntax, if/else statements, and while/for loops with examples.

  • programming statements
  • assignment statements
  • programming syntax
  • if else statements
  • while loops
  • for loops

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:03

    Hi, I’m Carrie Anne, and welcome to CrashCourse Computer Science!

  2. 0:05

    Last episode we discussed how writing programs in native machine code, and having to contend

  3. 0:09

    with so many low level details, was a huge impediment to writing complex programs.

  4. 0:14

    To abstract away many of these low-level details, Programming Languages were developed that

  5. 0:18

    let programmers concentrate on solving a problem with computation, and less on nitty gritty

  6. 0:22

    hardware details.

  7. 0:23

    So today, we’re going to continue that discussion, and introduce some fundamental building blocks

  8. 0:28

    that almost all programming languages provide.

  9. 0:30

    INTRO

  10. 0:40

    Just like spoken languages, programming languages have statements.

  11. 0:43

    These are individual complete thoughts, like “I want tea” or “it is raining”.

  12. 0:47

    By using different words, we can change the meaning; for example, “I want tea” to

  13. 0:51

    “I want unicorns”.

  14. 0:52

    But we can’t change “I want tea” to “I want raining” - that doesn’t make

  15. 0:54

    grammatical sense.

  16. 0:55

    The set of rules that govern the structure and composition of statements in a language

  17. 0:59

    is called syntax.

  18. 1:00

    The English language has syntax, and so do all programming languages.

  19. 1:03

    “A equals 5” is a programming language statement.

  20. 1:06

    In this case, the statement says a variable named A has the number 5 stored in it.

  21. 1:10

    This is called an assignment statement because we're assigning a value to a variable.

  22. 1:13

    To express more complex things, we need a series of statements, like “A is 5, B is

  23. 1:18

    ten, C equals A plus B”

  24. 1:20

    This program tells the computer to set variable ‘A’ equal to 5, variable ‘B’ to 10,

  25. 1:25

    and finally to add ‘A’ and ‘B’ together, and put that result, which is 15, into -- you

  26. 1:29

    guessed it -- variable C.

  27. 1:31

    Note that we can call variables whatever we want.

  28. 1:33

    Instead of A, B and C, it could be apples, pears, and fruits.

  29. 1:36

    The computer doesn’t care, as long as variables are uniquely named.

  30. 1:39

    But it’s probably best practice to name them things that make sense in case someone

  31. 1:42

    else is trying to understand your code.

  32. 1:44

    A program, which is a list of instructions, is a bit like a recipe: boil water, add noodles,

  33. 1:49

    wait 10 minutes, drain and enjoy.

  34. 1:50

    In the same way, the program starts at the first statement and runs down one at a time

  35. 1:55

    until it hits the end.

  36. 1:56

    So far, we’ve added two numbers together.

  37. 1:58

    Boring.

  38. 1:59

    Let’s make a video game instead!