Copyright

Action Statements: Definition & Examples

Instructor: Martin Gibbs

Martin has 16 years experience in Human Resources Information Systems and has a PhD in Information Technology Management. He is an adjunct professor of computer science and computer programming.

Any good computer program should actually DO something. It's up to the programmer to tell it what to do. Action statements are commands. This lesson will define the term and provide working code examples.

Action

We write programs to solve problems. In order to solve the problem, we need a set of steps to carry out. Each step that tells the program what to do is an action statement. These are the commands we want the program to complete. Sometimes they are nested within other, non-action statements.

In most programming languages, such as Java, C/C++, Pascal, and SQL, an action statement ends with a semicolon (;). This is very important! Programmers have been known to pull out clumps of hair looking for a bug in their program, only to find they missed a semicolon!

There are unlimited possibilities for the actions that action statements can complete. Here are just a few of the high-level functions that are carried out by action statements:

  • Display output on the screen
  • Create a new variable
  • Update a variable
  • Read a file
  • Write a file
  • Stop execution/break

Action statements are the commands that the program carries out. In contrast, other statements may check for a value, or repeat a set of instructions. These are called conditional statements, and looping statements, respectively. Statements that begin with 'if' or 'for' do not specifically carry out a task, but the statements WITHIN those blocks of code can.

The focus of this lesson is the ACTION. We want the program to perform a task. Our action statements may be nested within blocks of other statements and it may not ever be completed! This isn't always bad. If you are testing for a divide-by-zero error, it is a good thing if your program never needs to execute the action statements you developed.

Action Statements

The following is a very simple example of an action statement. It is written in C++ and displays a simple output on the screen.


C Basic Action Statement


Here is a basic statement, written in Java. It sets the value of a variable to 17.


Java basic action statement


Let's add a little more complexity to our statements. We will embed an action statement in a conditional statement (a test for the value of a variable). The following example checks to see if our counter is less than 20. If it is, it carries out the action statement.


Action statement with conditional


Which one is the action statement? That's right, the line that prints a value to the screen. Note that it ends with a semicolon!

Action Statements with Style

Another important note on statements and style is how programming statements are formatted and displayed. Be sure to INDENT action statements. That is, if you have a conditional statement, indent the action statement(s) that follow. Also, place each statement on its own line. It makes it easy for you and others to understand your code!

To unlock this lesson you must be a Study.com 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 Study.com

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

Earning College Credit

Did you know… We have over 200 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? Study.com 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
Support