HP Prime for All

English  Русский 

Author: Edward Shore (original article)

This is the first issue of a series of tutorials for the HP Prime, written by Edward Shore. If you have programmed with the HP 39g, 39g or 39gII, you will recognize the programming as the HP Prime programming language (HPPP) is similar. We are using the latest firmware in this series, available on the website.

How to start?

  1. Press S + 1 (Program).
  2. Press New. It is the second touch key.
  3. Enter the name of the program. Pressing the A key twice will turn on UPPERCASE ΑLPHA-LOCK. Pressing ASA will turn on lowercase alpha-lock. To exit any lock, press the A key one more time. When you’re happy with the name, press E.

Rules for Program Names:

  1. Letters, numbers, and the underscore character (_) only.
  2. The program name must start with a letter.

Structure of a HP Prime Program

A HPPP program is encased of an EXPORT - BEGIN - END structure. The layout is generally like this:

EXPORT program_name(arguments)
BEGIN commands and comments go here

Each line containing a command generally must end with a semicolon (;).
A semicolon can by type by pressing A then the +

Comments can be typed. They are designated by two forward slashes. The slashes are typed by pressing the /.

Anything in the line following the two slashes is ignored in running the program.


TIP: You can check the syntax of the program just by pressing the Check soft key in the program editor. HP Prime will Inform you if there is a syntax error and attempt to point you to the error. If there are no syntax errors, the Prime states "No errors in the program". I use the Check Command all the time.

Our first program is SQIN, because "Hello World" programs are so 2000s. SQIN takes a number, squares it, then calculates the reciprocal. In short we are defining a custom function:



RETURN returns a result to the stack (home page). You can return numbers, lists, vectors, matrices, strings, or a combination of these times.

Access: Tmplt 1(Block) 2(RETURN)


How to run the programs:

Home Mode - Textbook Entry, Home Mode - Algebraic Entry, CAS Mode:

Type the program name. Follow the name with parenthesis and enclose the required arguments.

Or use the b key, select the User touch key, select the program, and input the required arguments.

Home Mode - RPN Entry:

Enter each argument, separate each entry by pressing the E. Type the name, and in the parenthesis state the number of arguments.

For example, if the program TEST has four arguments, the RPN stack would like this:

4: argument_1
3: argument_2
2: argument_3
1: argument_4

TEST(4) to run the program.

Examples to try with SQIN:
SQIN(5) returns .04
SQIN(36) returns .000771604938


LOCAL: Declares any variables to be local to the program. In other words, the variables are created, used, possibly displayed during program execution, and deleted at program termination.

Access: Tmplt 4(Variable) 1(LOCAL)

MOPMT calculates the monthly payment of a loan. The arguments are: the loan amount (L), the interest rate (R), and the number of months (M).

TIP: You can declare local variables and assign an initial value at the same time. For example: LOCAL K:=1; stores 1 in K and makes K a local variable.

BEGIN LOCAL K := R/1200;
K := L*K / (1 - (1+K)^-M);
RETURN "Payment = " + K;

TIP: Use RETURN, TEXTOUT_P, and PRINT to return custom strings, which combine results, messages, and calculations. Parts are connected with a plus sign.

MOPMT(4000, 9.5, 30) returns 150.317437565
MOPMT(370000, 3.5, 360) returns 1661.46534383

Try this and next time in the series I will highlight other things we can do with HPPP.

Read Part 2 >