Statement in Programming (SP)

As mentioned above, statements are part of a program that contains commands to be executed/run. Therefore, these statements determine how the program runs and how a variable value is manipulated/changed. Statements can be grouped into, among others:

  1. Simple Statement
  2. Compound Statement
  3. Selection Statement
  4. Iteration Statement.

1. Simple Statement

Those that are classified as simple statements are statements that do not contain other statements, as follows:

Assignment Statement

This is a statement used to assign a value to a variable, for example in Pascal (left) and C (right):

Statement for calling a function or procedure

That is a statement that calls a function or procedure that has been defined in the program. Examples of calling procedures and functions in Pascal and C (assuming the Calculate, Cetak, and GetLength procedures for the examples below have been defined first):

Jump Statement

It is a statement that is used to skip other statements. Included in this statement category are:

2. Compound Statement

A compound statement is a group of statements that consists of other statements, including iteration and selection statements which will be discussed below. In the Pascal language, a collection of statements begins with the keywords begin and is closed by the keyword end, whereas in the C language, a collection of statements begins and ends with curly brackets { and }. The following is an example of a compound statement:

3. Selection Statement

Performs value/condition checks, which then selects which statement to execute. This statement consists of 2 types, namely: if..then..else statement and case/switch statement. Here is how to write a selection statement in Pascal and C languages:

4. Iteration Statement

Iteration statements are used to repeat a set of statements (compound statements). Iteration statements in Pascal and C are as follows:


Post a Comment

Previous Next

نموذج الاتصال