Kamis, 20 Januari 2011

SELECTION CONDITIONS

SELECTION CONDITIONS
1. Preliminary In the real world, sometimes a person faced with a choice, and he must accept the consequences of each choice. The same will often found in computer programming, it can even be said that all the programs that are complex would include aspects that affect the selection of a continuation course of the program. In programming with any language, it is often referred to as selection conditions, or branching (branch). By doing the selection condition, the program can determine what action should be done, depending on the results of these selected conditions. 


In the language Pascal, selection conditions can be done in 2 ways, namely using reserve word IF .. then and Case .. of. If reserve word .. then used to conduct the selection conditions with 1 or 2 option. While the word reserve Case .. of commonly used when the conditions will make the selection of several options at once (more than 2 options). If a backup does not mean the word .. then not be used for screening the condition of more than 2 choices, but using the Case .. of will be more efficient when dealing with the selection conditions for more than 2 choices. 


Both in the If .. Case then well .. of, an action will only be executed if the determining condition is reached (is true), and will not be executed if the determining condition is not met (false). If there are alternative choices of action and conditions are suitable, then the action is executed. If there are no appropriate conditions at all, then none of the action choices that will be executed. Sometimes the choice of the last action is required if none of the conditions are met.
2. The word used reserve Program: The specification name of the program and its parameters, is decorative and not affect the overall program itself Uses: define the name of the unit to be referenced by the program Var: linking an identifier and its type with a location in memory where the values of these types can be stored Begin: starting a program block End: end a program block If: mention the conditions for a statement that can be executed Then: mention the statement of action must be executed when the conditions are met Else: mention the statement of actions that can be executed while another action statement is not executed because the condition is not fulfilled Case: mention the statement expression that searches for the appropriate conditions based on the condition of the available options statement Of: the word is used in conjunction Case reserves to mention the choice of appropriate conditions and actions to be executed when a condition selected Or: logical operators that can be used to assist the selection condition
3. The procedure used Write: writing a variable into a component file in a text file used to write one or more values to a file Writeln: executing the write procedure, then pulled out a marker of end-of-line (EOL) to the program files Read: read a file into a variable component, in a text file used to read one or more values into one or more variables Readln: executes a read procedure, and then move to the next line in program files
4. Functions used Sqrt: root value of an argument 



ex.. simple program. 

Program m3c1;
Uses wincrt;
Var
a, b, c, max : integer;
Begin
     Writeln ('Masukkan 3 bilangan: ');
     Readln (a,b,c);
      Writeln;
     If a > b then
            if a > c then
                  max := a
            else
                  max := c
     else
            if b > c then
                  max := b
            else
                  max := c;
Writeln ('Bilangan terbesar: ',max);

Tidak ada komentar:

Posting Komentar