CouldnoT Posted October 30, 2020 Share Posted October 30, 2020 (edited) Ordinal types Ordinal types are integer values that use literal indications instead of numbers. For example, if we need to define language variables (Romanian/English/French) we could use the value 1 for Romanian, 2 for English, and 3 for French. Other programmers wouldn't know the values for 1, 2 and 3 unless they find comments with these values. It will be more readable if we do it with ordinal types as in the below example: program OrdinalTypes; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes { you can add units after this }; type TLanguageType = (ltRomanian, ltEnglish); var Lang: TLanguageType; AName: string; Selection: Byte; begin Write('Please select Language: 1 (Romanian), 2 (English)'); Readln(Selection); if Selection = 1 then Lang:= ltRomanian else if selection = 2 then Lang:= ltEnglish else Writeln('Wrong entry'); if Lang = ltRomanian then Write('Cum te numești: ') else if Lang = ltEnglish then Write('What is your name: '); Readln(AName); if Lang = ltRomanian then begin Writeln('Salut, ' , AName); Write('Vă rugăm să apăsați tasta Enter pentru a închide'); end else if Lang = ltEnglish then begin Writeln('Hello ', AName); Write('Please press enter key to close'); end; Readln; end. Integer, character and Boolean types are ordinal types, while real numbers and strings are not. Edited October 30, 2020 by CouldnoT Link to comment Share on other sites More sharing options...
CouldnoT Posted November 3, 2020 Author Share Posted November 3, 2020 Link to comment Share on other sites More sharing options...
Recommended Posts