Algorithmic Languages (Basic)
0. Algorithm
An algorithm is a finite sequence of definite steps . Should be general (generality), with input and output (portability).
The clarity of the ps algorithm steps is a relatively subjective property.
1. Three main rules
Algorithm is actually a finite sequence of compound steps given some basic steps or combined according to some rules.
There are three main rules for combining basic steps into compound steps:
1) Sequential structure : one or more steps of the algorithm are executed sequentially in the order in which they are written;
2) Selective structure : the algorithm contains conditions, and different steps are selected and executed according to whether the conditions are met during execution;
3) Loop structure : One or more steps of the algorithm are repeated when a certain condition is met.
2. Description of the algorithm
The basic way to describe algorithms: use structured natural language to describe algorithms
1) Select structure: if(条件)then...else...end
only then and no else branch can be used, at this time it isif(条件)then...end
If a branch has only one step, do not break the line and omit end, if there are multiple steps, indent, and use end to mark the scope of the entire branch structure.
2) Loop structure: while (condition) do...end, where the steps between do and end are called loop body.
If the loop body has only one step, do not break the line and omit end, if there are multiple steps, indent, and use end to indicate the scope of the loop body.
The form is also sometimes used for(条件)do...end
to give a looping structure. The condition usually refers to a range of values of an integer, or to all elements in a particular set or sequence.
返回
3) Chinese or English keywords can be used return
to give the content returned by the algorithm as the output of the algorithm, and the algorithm will terminate after this step is executed.
In addition, the basic operations of the algorithm, including assignment, arithmetic operation, logical operation, relational operation, conditional judgment, sub-algorithm call, etc., can be flexibly described in natural language.