0
$\begingroup$

In the context of compilers, what exactly is a loop variable (if there is a standard definition)?

Every read/write make up for the loop variable, or only writes make them up? Or is it writes in the body and reads in the condition?

$\endgroup$

2 Answers 2

1
$\begingroup$

The term that I was taught (thanks, Dragon Book!) is "induction variable". It refers to any variable which is a linear function of the number of iterations in a loop.

I don't know the term "loop variable", but if I had to guess, it would refer to a variable whose value changes inside the loop, and which is tested to decide the loop termination condition.

But to be honest, it would depend what you were trying to use it for. Pick whatever definition helps your analysis.

$\endgroup$
1
  • $\begingroup$ Yes, thanks for the answer :). I knew about the induction variable, but in an open-source project, there was a function that was supposed to return "loop variables". Hence, the question. Anyways, I will ask the code owner for the meaning there. $\endgroup$ Apr 29, 2020 at 3:13
0
$\begingroup$

Usually a variable which is used for the control of a loop. Basically a counter (as in a for/next-style loop), but can play a more general role.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.