CouldnoT Posted May 29, 2020 Share Posted May 29, 2020 (edited) For loop You can execute for statements for a specific number of cycles using a counter like this example: var i: Integer; Count: Integer; begin Write('How many times? '); Readln(Count); for i:= 1 to Count do Writeln('Hello there'); Write('Press enter key to close'); Readln; end. We should use ordinal types like Integer, Byte, and Char in for loop variables. We call this variable a loop variable or loop counter. The value of loop counter can be initialized with any number, and we can also determine the last value of loop counter. For example, if we need to count from 5 to 10, then we can do this: for i:= 5 to 10 do We can display loop counter in every cycle of the loop, as in the modified example below: var i: Integer; Count: Integer; begin Write('How many times? '); Readln(Count); for i:= 1 to Count do begin Writeln('Cycle number: ', i); Writeln('Hello there'); end; Write('Press enter key to close'); Readln; end. Note: that this time we need to repeat two statements, and for that reason we have used the begin . . end keywords to make them one statement. Edited May 29, 2020 by CouldnoT Link to comment Share on other sites More sharing options...
Clanin3 Posted June 2, 2020 Share Posted June 2, 2020 Topic inactiv. Link to comment Share on other sites More sharing options...
Recommended Posts