Lesson: Statements

Overview: 
Explore the concept of Statements in a programming language and how they are used in Java.
Objectives: 

Understand the concept of statements and in particular how statements are used in Java. Understand using variables and statements to perform basic math operations.

Content: 

Statements are the work horse construct of any text based programming language. Statements are where action happens and where you encode your algorithm into instructions for your robot. Statements fall into two categories, actions with assignment of a resulting value to a variable and actions that do not assign a result:

Note there is always only one item, a variable, on the left side of the assignment operator. You cannot have operations on the left side of the = sign: think ‘assignment’ not equals! You can control the order of operations with parenthesis:

Operators are used  to manipulate variables in a statement. Operators have an order of evaluation called precdence (more), at the same parenthetic level. In the above example, multiplication is done before addition. Watch this video up to comparison operators (discussed later). The various math operators available are discussed here and here (arithmetic and assignment sections).

Statements can span more than one line and continue until terminated with a semicolon. Statements (other than variable declarations) only appear inside methods. We will discuss methods a bit later.

Here is a quiz on variable assignment statements.

 

Lesson navigation: