📄 9.2.4.1.htm
字号:
<html>
<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>
<BODY>
<table align=right width=300>
<tr>
<td>
<img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='9.2.4.htm'" ></img></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='9.2.4.2.htm'" ></img></td>
</tr>
</table>
<br><br>
<font class="title2">9.2.4.1 代码外提</font><br>
<table>
<tr>
<td>    </td>
<td class="content">
<p>
减少循环中代码总数的一个重要办法是<font class = "definition2">代码外提</font>。这种变换是把循环不变计算(即产生的结果独立于循环执行次数的表达式)放到循环的前面。(注意:这里隐含着循环只存在一个入口)
</p>
</td>
</tr>
</table>
<table><tr><td>    </td>
<td class="content">
<p>
例如:下面是一个while语句:
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
         <font color="#0000FF">while</font>( i <= limit - 2 )<br>
             循环体<br>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<p>
假设while的循环体不改变limit的值,那么limit-2是循环不变计算。代码外提的结果是:
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<p>
         t = limit - 2;<br>
         <font color="#0000FF">while</font> ( i<=t )<br>
             循环体
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<p>
当然while的循环体也不改变t的值。
</td></tr></table>
<br>
<table align=right width=300>
<tr>
<td>
<img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='9.2.4.htm'" ></img></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='9.2.4.2.htm'" ></img></td>
</tr>
</table>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -