Programming Basics – Condition Testing

When writing a program, there are many occasions where an action needs to take place due to the triggering of an event. This requires the programming language to possess the ability to evaluate situations and take action. In programming terms, this ability is described as
Condition Testing.

Condition Testing exists in all programming, but in different forms. The evaluation they do is the same, but how they are represented in the code is very different. In languages like Modula, Pascal and BASIC (which are also known as Procedural Languages) condition testing is found in the form of IF, THEN and ELSE.

The IF and THEN condition are the most commonly used of condition testers. The format of a statement would be as follows: IF <condition> THEN <action>

Here <condition> refers to any type of validation. The validation is the comparison of a value against an expression. The value can be either a variable, constant, expression or function result. Based on this comparison, the condition will execute the action.
For example in Pascal:

IF Age>17 THEN
Begin
WriteLn (“You are an Adult”);
End

To test multiple statements an ELSE statement is used in two ways. To immediately execute an action based on the failure of the IF statement or to initiate another IF statement.
For example in Pascal:

IF Age>17 THEN
Begin
WriteLn (“You are an Adult”);
End
ELSE
Begin
WriteLn (“You are not yet an Adult”);
End

Another example would be:

IF Age>17 THEN
Begin
WriteLn (“You are an Adult”);
End
ELSE IF age>13
Begin
WriteLn (“You are a teenager”);
End

These are the basics of Condition Testing. The more advanced sections will enable you to conduct intensive and complicated testing of statements.

No Comments Yet

Leave a Reply

Your email address will not be published. Required fields are marked *

Archives