关于特殊for循环的问题 [英] Question about a special for loop

查看:77
本文介绍了关于特殊for循环的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

以下for循环中存在条件的含义是什么:



hello
what's the meaning of the existance condition in the following for loop:

for (unsigned long long number = 1, n = number, ub = 2 << (nrows - 1); number < ub; n = ++number)





我尝试了什么:



以下for循环中存在条件的含义是什么:



What I have tried:

what's the meaning of the existance condition in the following for loop:

推荐答案

你不明白你的代码在做什么。



有一个几乎通用的解决方案:运行你的代码在调试器上一步一步,检查变量。

调试器在这里向你展示你的代码正在做什么,你的任务是与它应该做什么进行比较。

没有魔法调试器,它不知道你应该做什么,它没有找到错误,它只是通过向你展示发生了什么来帮助你。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。

调试器 - 维基百科,免费的百科全书 [ ^ ]



掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]

调试器只是为了显示你的代码正在做什么,你的任务是与它应该做什么进行比较。
You don't understand what your code is doing.

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.


它是一个标准的 loop:

it's a standard for loop:
for ( a; b; c)
   d;

在你的情况下 a 是三个初始化者:

In your case a is three initialisers:

unsigned long long number = 1, 
n = number, 
ub = 2 << (nrows - 1)

b 是一个简单的布尔测试:

b is a simple boolean test:

number < ub

c 是一个基本的(如果相当愚蠢)增量器:

And c is a basic (if rather silly) incrementer:

n = ++number

除非在循环内修改 n ,否则它将保持步骤 number 并且可以被淘汰。

Unless n is modified inside the loop, it will maintain step with number and could be eliminated.


这篇关于关于特殊for循环的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆