Programming Logic & Syntax: The Programming Toolbox

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: Using Pseudocode to Map Code

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
Your next lesson will play in 10 seconds
  • 1:26 Statements
  • 1:56 Variables
  • 3:08 Keywords
  • 3:43 Controlling Workflow
  • 6:16 Comments
  • 7:03 Lesson Summary
Add to Add to Add to

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Login or Sign up


Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Paul Zandbergen

Paul has a PhD from the University of British Columbia and has taught Geographic Information Systems, statistics and computer programming for 15 years.

A programming language has its own syntax that dictates how words and symbols can be put together to form a program. Learn about programming's use of statements, variables and keywords in this video lesson.

Programming Syntax

Programming is a creative process carried out by programmers to instruct a computer on how to do a task. A program is a set of instructions that tells a computer what to do in order to come up with a solution to a particular problem. The actual content of the program is called code. That is why programming is often referred to as coding or writing code.

Code is written in a language that a computer can understand. There are hundreds of different programming languages, each with their own logic and syntax. A programming language has its own syntax, which consists of the set of rules that dictate how words and symbols can be put together to form a program.

The concept of syntax in programming language is similar to the concepts of grammar and spelling in spoken language. When a sentence in English has very poor grammar and spelling, it becomes difficult or even impossible to understand. Similarly, when code has syntax errors, the program will not execute.

The difference is that when you read a sentence in English with a minor error, you can typically still understand its meaning. Very small syntax errors in code, however, make the program unusable. Coders, therefore, have to pay great attention to detail to make sure their code is not only logical but also free of syntax errors. There are a number of aspects to syntax, including statements, variables and keywords.


Statements are the basic unit of code. A statement can assign a value to a variable, perform a single action, control the execution of other statements and do any number of other things. A statement consists of a single line of code that does something. A very simple example of a statement is the following:

print 'Hello world!'

When executed, this print statement prints the text 'Hello world!' to the screen, just as you might have expected.


Programming languages use variables. You can think of a variable as a container in which you can store a value that can be retrieved at any time. In other words, variables store information. Let's consider a very simple example:

x = 17

The variable is x, and you assign the value of 17 to this variable. This is an assignment statement. Once you assign a value to a variable, you can use the variable to do something else. For example:

x * 2

Once you run this code, you get the result 34.

Variables can contain any valid data type, including strings, numbers, Boolean values, lists, arrays and others. For example, here is how you could use a string variable:

mytext = 'Hello world!'

Variable names can be just about anything, but they typically cannot start with a number since the first part of the variable would be confused with a number. Now you can do something with this string. For example, the following code:

print mytext

This will print the value of the variable 'mytext' to the screen, so 'Hello world!'


Programming languages use keywords. A keyword is a term that has a specific meaning within that programming language. For example, the command 'print' in the previous example is a keyword. As you might have guessed, this keyword prints whatever comes after it to the screen. Another example of a keyword would be 'import,' used to import something so that it can be used in the program. Keywords are reserved, meaning that you cannot use them for anything else. For example, you cannot create a variable called 'import,' since this would get very confusing.

Controlling Workflow

You can think of a computer program as a series of statements that are executed line-by-line. By default, lines are executed in a simple sequence from the first line to the last line, unless there is a statement that tells the execution to jump to somewhere else in the code. A number of different statements are used to control the execution of part of the program.

A conditional statement allows for choosing between two or more execution paths. A conditional statement is also sometimes referred to as a selection statement or branching. For example, an 'if' statement is used to execute a block of code when a particular condition is true. If the condition is false, the block of code is skipped and the rest of the code in the program is executed. A variation on this is the 'if-else' statement. The block of code following the 'else' statement is executed if the 'if' statement is false.

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 160 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create An Account