![]() CATEGORIES: BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism |
Syntax of the REPEAT - UNTILREPEAT statement(s) UNTIL boolean condition is TRUE Program 4 PROGRAM repeat_until(INPUT,OUTPUT); { a demonstration program for the repeat - until loop } VAR condition, colour : string[10]; BEGIN REPEAT WRITE('Enter light colour : '); READLN(colour); WRITE('Is crosswalk occupied or clear : '); READLN(condition); UNTIL ((colour = 'green') and (condition = 'clear')) or ((colour = 'orange') and (condition = 'clear')); WRITELN('You can go now'); END. { program repeat_until }
Program 5 PROGRAM ascii(INPUT,OUTPUT); { the program which wrote out the ASCII table in the back of this book } VAR I : INTEGER; BEGIN I := 32; WRITE(' '); WRITELN('ASCII TABLE'); WRITELN; REPEAT WRITE(' ',I:3,' = ',CHR(I),' '); WRITE(I+1:3,' = ',CHR(I+1),' '); WRITE(I+2:3,' = ',CHR(I+2),' '); WRITE(I+3:3,' = ',CHR(I+3),' '); WRITELN(I+4:3,' = ',CHR(I+4),' '); I := I+5; WRITELN; UNTIL I = 127; END. { program ascii }
Program 6 PROGRAM password(INPUT,OUTPUT); { a password demonstration program } CONST good_password = '!42a'; { can be anything } VAR pass_word : string[4]; BEGIN WRITELN; WRITELN(' This is a restricted use machine'); WRITELN('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'); WRITELN; REPEAT WRITE('Please enter PASSWORD : '); READLN(pass_word); IF pass_word <> good_password THEN WRITELN('access DENIED, try again'); UNTIL pass_word = good_password; WRITELN; WRITELN('Password ACCEPTED, continue'); WRITELN; WRITELN(' Welcome to the World Bank Data Base'); WRITELN('-------------------------------------'); END. { program password }
5. Looping : FOR - TO - DO The FOR loop is another very powerful control structure in any programming language. What a FOR loop does is to execute a statement or group of statements a known number of times. Date: 2016-03-03; view: 838
|