Difference between revisions of "Basic Pascal Tutorial/Chapter 5/Subranges"
From Lazarus wiki
Jump to navigationJump to searchm (Text replace - "delphi>" to "syntaxhighlight>") |
m (bypass language bar/categorization template redirect [cf. discussion]) |
||
(7 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Basic Pascal Tutorial/Chapter 5/Subranges}} | ||
+ | {{TYNavigator|Chapter 5/Enumerated types|Chapter 5/1-dimensional arrays}} | ||
+ | |||
5B - Subranges (author: Tao Yue, state: unchanged) | 5B - Subranges (author: Tao Yue, state: unchanged) | ||
A ''subrange'' type is defined in terms of another ordinal data type. The type specification is: | A ''subrange'' type is defined in terms of another ordinal data type. The type specification is: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
lowest_value .. highest_value | lowest_value .. highest_value | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 9: | Line 12: | ||
For example, you may want to declare the days of the week as well as the work week: | For example, you may want to declare the days of the week as well as the work week: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
type | type | ||
DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday, | DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday, | ||
Line 18: | Line 21: | ||
You can also use subranges for built-in ordinal types such as <tt>char</tt> and <tt>integer</tt>. | You can also use subranges for built-in ordinal types such as <tt>char</tt> and <tt>integer</tt>. | ||
− | {| | + | {{TYNavigator|Chapter 5/Enumerated types|Chapter 5/1-dimensional arrays}} |
− | |||
− | | | ||
− | |||
− |
Latest revision as of 16:20, 20 August 2022
│
български (bg) │
English (en) │
français (fr) │
日本語 (ja) │
中文(中国大陆) (zh_CN) │
5B - Subranges (author: Tao Yue, state: unchanged)
A subrange type is defined in terms of another ordinal data type. The type specification is:
lowest_value .. highest_value
where lowest_value < highest_value and the two values are both in the range of another ordinal data type.
For example, you may want to declare the days of the week as well as the work week:
type
DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,
Thursday, Friday, Saturday);
DaysOfWorkWeek = Monday..Friday;
You can also use subranges for built-in ordinal types such as char and integer.