📄 scripting_5_6__arrays.html
字号:
<html><head><meta name="robots" content="index,follow">
<title>脚本 5.6. 数组</title></head><body bgcolor="#FFFFFF">
<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b>
脚本 5.6. 数组
</b></font></table></table>
<p>
可以用单引号置换机制来模拟变量的数组:</p>
<code>
<b>for</b> i <b>from</b> 1 <b>to</b> 5<br></code>
<code>
square'i' = i * i<br></code>
<code>
<b>endfor</b><br></code>
<p>
上面的脚本执行之后,变量<i>square1</i>、<i>square2</i>、<i>square3</i>、<i>square4</i>和<i>square5</i>将相应地含有1、4、9、16和25这几个值。</p>
<p>
脚本并不限制使用变量的数目,但除此之外还可以利用Matrix(矩阵)或者Sound(声音)对象表示数组。</p>
<p>
用单引号就可以常规地置换变量,比如<code>'square3'</code>。而如果其中的索引也是个变量,则可能需要用到一个临时变量:</p>
<code>
<b>echo</b> Some squares:<br></code>
<code>
<b>for</b> i <b>from</b> 1 <b>to</b> 5<br></code>
<code>
<b>hop</b> = square'i'<br></code>
<code>
<b>printline</b> The square of 'i' is 'hop'<br></code>
<code>
<b>endfor</b><br></code>
<p>
之所以要这么做,因为像下面这样的脚本是不能用的——没有双重置换的机制:</p>
<code>
<b>print</b> The square of 'i' is 'square'i''<br></code>
<h3>指向本页的链接</h3>
<ul>
<li><a href="Scripting.html">脚本</a>
<li><a href="Scripting_5__Language_elements.html">脚本 5. 语言元素</a>
</ul>
<hr>
<address>
<p>© ppgb, June 24, 2002</p>
<p>© 翻译:徐清白,2005年05月31日</p>
</address>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -