Skip to content

TO


用于指定范围的语句修饰符。

语法

vb
For iterator intial_value To ending_value

statement(s).

Next [ iterator ]

or
Select Case case_comparison_value
Case lower_bound To upper_bound

statement(s).

End Select

or
Dim variable_identifier( lower_bound To upper_bound ) As type_specifier

说明

To 关键字用于定义特定的数值范围。该关键字仅在与 For ... NextCaseDim 语句一起使用时有效。

在第一种语法中,To 关键字定义 For 语句中迭代器的初始值和结束值。

在第二种语法中,To 关键字定义 Case 比较的上界和下界。

在第三种语法中,To 关键字定义 Dim 语句中的数组边界。

有关更多信息,请参见 For...NextDimSelect Case

示例

start GeSHi

vb
'' this program uses bound variables along with the TO keyword to create an array, store random
'' temperatures inside the array, and to determine output based upon the value of the temperatures
Randomize Timer

'' define minimum and maximum number of temperatures we will create
Const minimum_temp_count As Integer = 1
Const maximum_temp_count As Integer = 10

'' define the range of temperatures zones in which bacteria breed rapidly (in degrees)
Const min_low_danger As Integer = 40
Const max_low_danger As Integer = 69
Const min_medium_danger As Integer = 70
Const max_medium_danger As Integer = 99
Const min_high_danger As Integer = 100
Const max_high_danger As Integer = 130

'' define array to hold temperatures using our min/max temp count bounds
Dim As Integer array( minimum_temp_count To maximum_temp_count )

'' declare a for loop that iterates from minimum to maximum temp count
Dim As Integer it
For it = minimum_temp_count To maximum_temp_count

   array( it ) = Int( Rnd( 1 ) * 200 ) + 1

   '' display a message based on temperature using our min/max danger zone bounds
   Select Case array( it )
      Case min_low_danger To max_low_danger
         Color 11
         Print "Temperature" ; it ; " is in the low danger zone at" ; array( it ) ; " degrees!"
      Case min_medium_danger To max_medium_danger
         Color 14
         Print "Temperature" ; it ; " is in the medium danger zone at" ; array( it ) ; " degrees!"
      Case min_high_danger To max_high_danger
         Color 12
         Print "Temperature" ; it ; " is in the high danger zone at" ; array( it ) ; " degrees!"
      Case Else
         Color 3
         Print "Temperature" ; it ; " is safe at" ; array( it ) ; " degrees."
   End Select

Next it

Sleep

end GeSHi

与 QB 的区别

另请参阅

  • For...Next
  • Dim
  • Select Case

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系