TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why are variables “i” and “j” used for counters?

2 点作者 marcog1超过 14 年前

2 条评论

davewiner超过 14 年前
Dates back to Fortran, a language that was designed primarily to work on real numbers, for scientific calculation. They needed whole numbers or "integers" -- but they didn't have the concept of type declarations yet (or it was a hodgepodge and non-standard) -- so they came up with a convention that variables whose names began with i through (some upper bound I don't remember) were integers.<p>Since loop indices are integers it made sense that their names should begin with I. If your outer loop's variable is named I and you all of a sudden need an inner loop, what are you going to name it? J of course. Which is how this convention began.<p>Obviously today's programming languages not only allow you to declare the types of variables, many of them support variable types depending on what's been stored in a variable. But this was at the dawn of the computer era, before such coolness had come about.
评论 #1973296 未加载
RiderOfGiraffes超过 14 年前
Dup: <a href="http://news.ycombinator.com/item?id=1971507" rel="nofollow">http://news.ycombinator.com/item?id=1971507</a><p>Many comments there.