C++ language instructions

C

In order to generate the desired results, a program has to handle the data in a well-specified way. The description of these actions is done using the programming language instructions.

The commands the program gives to the computer when the program is running are called instructions.

The C ++ language instructions are:
1. expression statement
2. the compound statement
3. the if statement
4. the switch statement
5. the break instruction
6. the while statement
7. the do-while statement
8. The instruction for

The C ++ language instructions are divided into two categories:

– Simple instructions
– Structure controls (structured)

Simple instructions do not contain any other instructions (expense statement assignment). The control instructions specify the order in which the program’s instructions are executed, controlling the runtime of the program.

a. Expression statement
The Attribution statement is intended for assigning variable values ​​or returning values ​​for functions.

Syntax: expression
Effect: Expression is evaluated.

Write the “;” character after an expression (assignment, call to a function)

b. The composite statement

It is a succession of statements followed by instructions enclosed between braces.
Syntax:
{ statements; instructions; }

Effect: Run the specified instructions in order.

c. The if statement

The conditional decisional instruction if performs the selection to execute a single instruction from several possible ones.
There are two forms of the if statement.

Form 1
Syntax:
if (statement) instruction1; else instruction2;

Effect:
-stage 1: logical expression is evaluated;
– step 2: if the value of logical expression is different from 0 (true), instruction1 is executed, and if the value produced is 0 (it is false), instruction2 is executed.

Form 2
Syntax:
if (logical expression)
instruction;

Effect:
Step 1:
the logical expression is evaluated;
Step 2:
if the value of the logical expression is different from 0 (the decayed) instruction is executed.

d. Switch instruction
The decision-making switch makes selecting for execution one single instruction from several possible ones.
The switch statement is a generalization of the decision if, nested decision instructions can replace it.
syntax
switch (logical expression) {case c1: instruction1; break c2: instruction2; break; …………….. case cn: instruction; break; [default: instruction + 1;]
Effect:
-stage 1: the logical expression is evaluated
– step 2: if it produces a value equal to ci, executes instruction i and terminates the execution of the switch statement, otherwise executes instruction n + 1.

e. Break
The break instruction is used in the switch decision instruction or in the repetitive instructions.
Syntax: break;
Effect:
determines unconditional output from the statement in which it appears (switch, while, do while or for).

f. The instruction while
The repeat statement while specifies that some instructions are executed several times.
The while statement is a repetitive statement:
-with the initial test;
-with no number of steps
syntax;
while (logic expression)
instruction
Effect;
step1: evaluate the logical expression
step2: if the value produced by it is true (other than 0), instruction is executed, then it goes to step 1, otherwise it has the value 0, the next step in the program is passed.

g. The do while statement
The repeat statement while do specifies that some instructions are executed several times.
The do while statement is a repetitive statement:
– with the final test
-with no number of steps

Syntax:
do
  instruction
while (expression logic);
step1: execute the statement
step2: logical expression is evaluated; if its value is 0, the execution ends; otherwise it goes to step 1.

h. Instruction for
The repetitive statement for specifies that some instructions are executed several times.
The for statement is a repetitive statement:
– with a known number of steps.
Syntax:
for (expression1; Expression2; Expression3)
instruction;
Effect:
step 1: evaluate expression1;
step 2: evaluate expression2; if it produces a value other than 0, an instruction is executed, then pass to step 3, otherwise the for statement ends;
step 3: evaluate expression3 and return to step 2.

Recent Posts

Archives

Categories