Difference between revisions of "Basic Pascal Tutorial/Chapter 5/Subranges"

From Free Pascal wiki
Jump to navigationJump to search
Line 2: Line 2:
  
 
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:
lowest_value .. highest_value
+
<delphi>
 +
lowest_value .. highest_value
 +
</delphi>
  
 
where <tt>lowest_value < highest_value</tt> and the two values are both in the range of another ordinal data type.
 
where <tt>lowest_value < highest_value</tt> 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:
 
For example, you may want to declare the days of the week as well as the work week:
<font color="#006699"><strong>type</strong></font>
+
<delphi>
  DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,
+
type
                Thursday, Friday, Saturday);
+
  DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,
  DaysOfWorkWeek = Monday..Friday;
+
                Thursday, Friday, Saturday);
 +
  DaysOfWorkWeek = Monday..Friday;
 +
</delphi>
  
 
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>.  

Revision as of 16:55, 5 January 2010

5B - Subranges (author: Tao Yue, state: unchanged)

A subrange type is defined in terms of another ordinal data type. The type specification is: <delphi> lowest_value .. highest_value </delphi>

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: <delphi> type

 DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,
               Thursday, Friday, Saturday);
 DaysOfWorkWeek = Monday..Friday;

</delphi>

You can also use subranges for built-in ordinal types such as char and integer.

previous contents next