我不明白为什么我在这种情况下使用字母 i
I don't Understand why I'm using the letter i in this situation
我刚刚开始在c++和工作在一个简单的控制台应用程序,和教练没有解释一些事情。在这一部分中,他说要编码
//increment the turn number
MyCurrentTry++;
//setup a return variable
FBullCowCount BullCowCount;
//loop through all letters in the guess
int32 HiddenWordLenth = MyHiddenWord.length();
for (int32 i = 0; i < HiddenWordLenth; i++) {
// compare letters against the hidden word
for (int32 j = 0; j < HiddenWordLenth; j++) {
// if they match then
if (Guess[i] == MyHiddenWord[i]) { //if they're in the same place
if (i == j) { // increment bulls
BullCowCount.Bulls++; // Incriment Bulls
}
else
{
BullCowCount.Cows++; //must be a cow
}
现在我明白这有点乱(对不起),但如果有人能解释为什么我使用i
和i
做什么(它是某种变量,还是什么?),我会非常感激。如果我的问题不清楚或者我做错了什么,请告诉我(老师说这个"I"最终会产生一个bug,但我想知道它的目的)
i
和j
只是for
循环中的反变量。他们也可以被命名为ingrid和john。它们的唯一用途是在循环迭代时充当计数器。
相关文章:
- 我是c ++的新手,你能解释一下在这种情况下的指针吗
- 在这种情况下,java对象是否可以调用本机函数
- 在这种情况下显式调用时,std::cout 如何更改析构函数的行为?
- 在这种情况下,我真的复制了字节还是复制了字符?
- 为什么在这种情况下,bool 类型的输出等于 0?
- 在这种情况下,如何传递成员函数而不是函数?
- 为什么在这种情况下递增阵列名称有效?
- 在这种情况下我应该使用哪种设计模式
- 为什么在这种情况下我需要 .template
- 在这种情况下,使用 string_view 是否会导致不必要的字符串复制?
- 我是否访问了已释放的内存,或者在这种情况下DrMemory报告不正确?
- 在这种情况下,"typename..."意味着什么?
- 为什么在这种情况下 x = 44?
- 在这种情况下是私有的吗?试图使操作员<<过载
- 在这种情况下,如何防止C++输出/控制台窗体关闭
- 为什么 lambda nullptr 取消引用在这种情况下有效?
- 为什么在这种情况下,前向声明不起作用?
- 为什么在这种情况下不调用我的虚拟函数实现?
- 在这种情况下,为什么模板即时深度超过限制?
- 我不明白为什么我在这种情况下使用字母 i