为什么变量"i"和"j"表示用于柜台? [英] Why are variables "i" and "j" used for counters?

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

问题描述

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

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

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

尽管常识告诉我它们就像X一样,用于表示未知值,但我不禁要认为一定有一个原因,使得每个人都一遍又一遍地以相同的方式进行教学.

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?

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

推荐答案

它最终来自数学:求和表示法传统上将 i 用于第一个索引,将 j 用于第二个,依此类推.示例(来自 http://en.wikipedia.org/wiki/Summation ):

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):

它也用这种方式来收集事物,例如,如果您有一堆变量x 1 ,x 2 ,... x n ,那么任意一个将称为x i .

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.

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

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

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

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