Control Structures - Module 3
3. Control Structures
In Pascal you can split Control Structures into multiple groups, and to make it easier to understand I will do so.
Excuse that poorly drawn graphic, maybe eventually I'll substitute it for a better looking one.
Condition or Selection group
These types of Control Structures decide to execute certain action from the actions programmed.
Loops and Cycles
These control structures repeat a set of instructions a determined amount of times or until a certain condition is met.
3.1. If... Then... Else;
IF {condition} THEN
{instructions1}
ELSE
{instructions2};
In the program above, if certain condition is met program will execute instructions1 however if that criteria is not met instructions2 will be executed.
Consider this example:
As you can see the writeln('I am younger than you') has no ; this is intentional. If there are two or more statements, you need to use a begin...end block.
Example:
There can be multiple conditions too, to do this use Else If...
Example:
This example also shows you how to use Jump instructions, we could easily do this with the other control structures, but to avoid confusion I did it like this.
If you encounter any problems, let me know.
Este comentário foi removido pelo autor.
ResponderEliminar