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

From Free Pascal wiki
Jump to navigationJump to search
(New page: 5B - Subranges A ''subrange'' type is defined in terms of another ordinal data type. The type specification is: lowest_value .. highest_value where <tt>lowest_value < highest_value</tt>...)
 
m (Fixed syntax highlighting)
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
5B - Subranges
+
{{Subranges}}
 +
{{TYNavigator|Enumerated_types|1-dimensional_arrays}}
 +
 
 +
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:
lowest_value .. highest_value
+
<syntaxhighlight lang=pascal>
 +
lowest_value .. highest_value
 +
</syntaxhighlight>
  
 
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>
+
<syntaxhighlight lang=pascal>
  DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,
+
type
                Thursday, Friday, Saturday);
+
  DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,
  DaysOfWorkWeek = Monday..Friday;
+
                Thursday, Friday, Saturday);
 +
  DaysOfWorkWeek = Monday..Friday;
 +
</syntaxhighlight>
  
 
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>.  
  
{|style=color-backgroud="white" cellspacing="20"
+
{{TYNavigator|Enumerated_types|1-dimensional_arrays}}
|[[Enumerated_types|previous]] 
 
|[[op_contents|contents]]
 
|[[1-dimensional_arrays|next]]
 
|}
 

Revision as of 01:31, 28 February 2020

български (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.

 ◄   ▲   ►