为什么变量“i"是“i"?和“j"用于计数器? [英] Why are variables "i" and "j" used for counters?

查看:31
本文介绍了为什么变量“i"是“i"?和“j"用于计数器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这似乎是一个绝对愚蠢的问题,但我太好奇了不想问......

为什么i"和j"成为大多数控制结构中用作计数器的变量?

虽然常识告诉我它们就像X一样,用于表示未知的值,但我不禁想到,为什么每个人都被一遍又一遍地以同样的方式教导,一定是有原因的.

是因为它实际上被推荐用于最佳实践或惯例,还是背后有一些晦涩的原因?

以防万一,我知道我可以给他们任何我想要的名字,而且变量名称并不相关.

解决方案

它最终来自数学:求和符号传统上使用 i 作为第一个索引,j 用于第二个,以此类推.示例(来自 http://en.wikipedia.org/wiki/Summation):><块引用>

它也被用于事物的集合,比如如果你有一堆变量 x1, x2, ... xn,那么任意一个将被称为 xi.

至于为什么会这样,我认为 SLaks 是正确的,因为 I 是 Index 中的第一个字母.

I know this might seem like an absolutely silly question to ask, yet I am too curious not to ask...

Why did "i" and "j" become THE variables to use as counters in most control structures?

Although common sense tells me they are just like X, which is used for representing unknown values, I can't help to think that there must be a reason why everyone gets taught the same way over and over again.

Is it because it is actually recommended for best practices, or a convention, or does it have some obscure reason behind it?

Just in case, I know I can give them whatever name I want and that variables names are not relevant.

解决方案

It comes ultimately from mathematics: the summation notation traditionally uses i for the first index, j for the second, and so on. Example (from http://en.wikipedia.org/wiki/Summation):

It's also used that way for collections of things, like if you have a bunch of variables x1, x2, ... xn, then an arbitrary one will be known as xi.

As for why it's that way, I imagine SLaks is correct and it's because I is the first letter in Index.

这篇关于为什么变量“i"是“i"?和“j"用于计数器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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