![]() CATEGORIES: BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism |
Syntax of the FOR loop using DOWNTOFOR counter_variable := initial_value DOWNTO termination_value DO instruction Program 10 PROGRAM char_list(INPUT,OUTPUT); { program writes out list of ASCII characters } VAR I : CHAR; { for loop counter } BEGIN FOR I := '2' DOWNTO '%' DO WRITELN('The character is : ',I); END. { program char_list }
6. Selection : CASE - OF The CASE statement is an interesting variation on the selection process performed by the IF statement. It is a little more difficult to grasp, but it makes a whole bunch of IF - THEN - ELSE statements redundant, and makes for a much tidier program. A general rule used to decide whether to use a CASE statement is: if you need more than one IF, then use CASE. This next program, is a simple CASE statement demonstration program. The VAR date is called, the case index, and the integers 1 - 28 are called, labels. It should be fairly clear to see that, when date equals, any of the label, the course of action decided on by the CASE statement is to write out the message, associated with that label. Program 11 PROGRAM date(INPUT,OUTPUT); { a simple date program using case statement } VAR date : INTEGER; BEGIN WRITE('Enter the date : '); READLN(date); CASE date OF 7, 14, 21, 28 : WRITELN('That day in February, 1994 is a Monday'); 1, 8, 15, 22 : WRITELN('That day in February, 1994 is a Tuesday'); 2, 9, 16, 23 : WRITELN('That day in February, 1994 is a Wednesday'); 3, 10, 17, 24 : WRITELN('That day in February, 1994 is a Thursday'); 4, 11, 18, 25 : WRITELN('That day in February, 1994 is a Friday'); 5, 12, 19, 26 : WRITELN('That day in February, 1994 is a Saturday'); 6, 13, 20, 27 : WRITELN('That day in February, 1994 is a Sunday'); END; { end of case statement } END. { program date }Date: 2016-03-03; view: 764
|