<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>循环 on My Blog</title>
    <link>http://localhost:1313/tags/%E5%BE%AA%E7%8E%AF/</link>
    <description>Recent content from My Blog</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    
    <managingEditor>3453434429@qq.com (ArenBase)</managingEditor>
    <webMaster>3453434429@qq.com (ArenBase)</webMaster>
    
    <copyright>本博客所有文章除特别声明外，均采用 BY-NC-SA 许可协议。转载请注明出处！</copyright>
    
    <lastBuildDate>Tue, 24 Mar 2026 00:00:00 +0000</lastBuildDate>
    
    
    <atom:link href="http://localhost:1313/tags/%E5%BE%AA%E7%8E%AF/index.xml" rel="self" type="application/rss&#43;xml" />
    

    
    

    <item>
      <title>C&#43;&#43;循环条件中后置运算符的循环次数分析</title>
      <link>http://localhost:1313/post/c&#43;&#43;%E5%BE%AA%E7%8E%AF%E6%9D%A1%E4%BB%B6%E4%B8%AD%E5%90%8E%E7%BD%AE%E8%BF%90%E7%AE%97%E7%AC%A6%E7%9A%84%E5%BE%AA%E7%8E%AF%E6%AC%A1%E6%95%B0%E5%88%86%E6%9E%90/</link>
      <pubDate>Tue, 24 Mar 2026 00:00:00 &#43;0000</pubDate>
      <author>3453434429@qq.com (ArenBase)</author>
      <guid>http://localhost:1313/post/c&#43;&#43;%E5%BE%AA%E7%8E%AF%E6%9D%A1%E4%BB%B6%E4%B8%AD%E5%90%8E%E7%BD%AE%E8%BF%90%E7%AE%97%E7%AC%A6%E7%9A%84%E5%BE%AA%E7%8E%AF%E6%AC%A1%E6%95%B0%E5%88%86%E6%9E%90/</guid>
      <description>
        <![CDATA[<h1>C++循环条件中后置运算符的循环次数分析</h1><p>作者：ArenBase（3453434429@qq.com）</p>
        
          <h2 id="一基本发现">
<a class="header-anchor" href="#%e4%b8%80%e5%9f%ba%e6%9c%ac%e5%8f%91%e7%8e%b0"></a>
一、基本发现
</h2><p>在C++的while循环中，使用后置递增(<code>n++</code>)或递减(<code>n--</code>)操作符时，循环次数与初始值有特定的数学关系：</p>
<table>
  <thead>
      <tr>
          <th>初始值</th>
          <th>循环条件</th>
          <th>循环次数</th>
          <th>是否有限</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>正数</td>
          <td><code>while(n--)</code></td>
          <td>n（初始值）</td>
          <td>是</td>
      </tr>
      <tr>
          <td>负数</td>
          <td><code>while(n++)</code></td>
          <td>n</td>
          <td>是</td>
      </tr>
      <tr>
          <td>非负数</td>
          <td><code>while(n++)</code></td>
          <td>无限（或直到溢出）</td>
          <td>否</td>
      </tr>
      <tr>
          <td>非正数</td>
          <td><code>while(n--)</code></td>
          <td>无限（或直到溢出）</td>
          <td>否</td>
      </tr>
  </tbody>
</table>
<h2 id="二底层原理">
<a class="header-anchor" href="#%e4%ba%8c%e5%ba%95%e5%b1%82%e5%8e%9f%e7%90%86"></a>
二、底层原理
</h2><h3 id="1-条件判断的隐式转换">
<a class="header-anchor" href="#1-%e6%9d%a1%e4%bb%b6%e5%88%a4%e6%96%ad%e7%9a%84%e9%9a%90%e5%bc%8f%e8%bd%ac%e6%8d%a2"></a>
1. 条件判断的隐式转换
</h3><p>C++中，所有条件表达式（if、while、for等）都会将结果隐式转换为<code>bool</code>类型：</p>
        
        <hr><p>本文2026-03-24首发于<a href='http://localhost:1313/'>My Blog</a>，最后修改于2026-03-24</p>]]>
      </description>
      
        <category>C&#43;&#43;</category>
      
    </item>
    
  </channel>
</rss>
