CrashCourse · @crashcourse
Programming Basics: Statements & Functions: Crash Course Computer Science #12
Uploaded June 8, 2017 · Length 11:57
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.
- 0:03
Hi, I’m Carrie Anne, and welcome to CrashCourse Computer Science!
- 0:05
Last episode we discussed how writing programs in native machine code, and having to contend
- 0:09
with so many low level details, was a huge impediment to writing complex programs.
- 0:14
To abstract away many of these low-level details, Programming Languages were developed that
- 0:18
let programmers concentrate on solving a problem with computation, and less on nitty gritty
- 0:22
hardware details.
- 0:23
So today, we’re going to continue that discussion, and introduce some fundamental building blocks
- 0:28
that almost all programming languages provide.
- 0:30
INTRO
- 0:40
Just like spoken languages, programming languages have statements.
- 0:43
These are individual complete thoughts, like “I want tea” or “it is raining”.
- 0:47
By using different words, we can change the meaning; for example, “I want tea” to
- 0:51
“I want unicorns”.
- 0:52
But we can’t change “I want tea” to “I want raining” - that doesn’t make
- 0:54
grammatical sense.
- 0:55
The set of rules that govern the structure and composition of statements in a language
- 0:59
is called syntax.
- 1:00
The English language has syntax, and so do all programming languages.
- 1:03
“A equals 5” is a programming language statement.
- 1:06
In this case, the statement says a variable named A has the number 5 stored in it.
- 1:10
This is called an assignment statement because we're assigning a value to a variable.
- 1:13
To express more complex things, we need a series of statements, like “A is 5, B is
- 1:18
ten, C equals A plus B”
- 1:20
This program tells the computer to set variable ‘A’ equal to 5, variable ‘B’ to 10,
- 1:25
and finally to add ‘A’ and ‘B’ together, and put that result, which is 15, into -- you
- 1:29
guessed it -- variable C.
- 1:31
Note that we can call variables whatever we want.
- 1:33
Instead of A, B and C, it could be apples, pears, and fruits.
- 1:36
The computer doesn’t care, as long as variables are uniquely named.
- 1:39
But it’s probably best practice to name them things that make sense in case someone
- 1:42
else is trying to understand your code.
- 1:44
A program, which is a list of instructions, is a bit like a recipe: boil water, add noodles,
- 1:49
wait 10 minutes, drain and enjoy.
- 1:50
In the same way, the program starts at the first statement and runs down one at a time
- 1:55
until it hits the end.
- 1:56
So far, we’ve added two numbers together.
- 1:58
Boring.
- 1:59
Let’s make a video game instead!


