Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
procedures
communitycreator

What is a procedure in Euphoria?

NDUKWE CHIDERA K.

Introduction

Euphoria is an interpreted language that is easy, flexible, and simple to get started with. It is used in building desktop applications and applications for other platforms. In Euphoria, a lot of subroutines exist that are inbuilt to the language and are available at every installation.

As a programmer, we have the ability to write a subroutine for use anywhere in our code. We can achieve this by writing:

  • A function
  • A procedure

Procedure

A procedure is a program structure in euphoria. It can contain sets of instructions to carry out computations that may need parameters.

Procedures are important because they enable developers to write reusable code blocks. These blocks can be used anywhere in the program. Procedures are similar to functions except that they do not return anything, unlike functions, which have return values.

General syntax of a procedure

procedure identifier(parameter)
// code to execute
end procedure

Syntax explained

  • We declare a procedure in the beginning by using the procedure keyword.
  • Next, we give a suitable identifier to the procedure.
  • We insert the parameters (if any) in the parentheses immediately after the identifier.
  • We then put down the code to be executed by the procedure.
  • Lastly, we end the procedure using the end procedure statement.

Afterward, to use the procedure, we simply call it by writing down its identifier followed by the parentheses with the parameters (if any), as shown below:

identifier(parameter)

Code

Let’s write a simple procedure that welcomes users to our program.


procedure greetings(sequence name)

    printf(1,"Welcome %s to Edpresso",{name})
    end procedure
 
    greetings("Friend")
Code for a simple procedure

Explanation

  • In line 2, we define the procedure greetings and give it a parameter of sequence type name.
  • In lines 4-5, we specify the action to be performed by the sequence.
  • In line 7, we call the defined procedure and assign a value Friend to the parameter name.

Whereas in a function, we can save the value of the executed code in a variable and return it to use in other expressions or functions, we can’t do this in a procedure, as the latter does not return a value.

RELATED TAGS

euphoria
procedures
communitycreator
RELATED COURSES

View all Courses

Keep Exploring