Say I have a program that swaps two variables:

1)read a
2)read b
6)print a
7)print b

I want to say that I swap the values of a and b on (or should it be at or in?) lines 3-5 of the program.

2 Answers 2


I would definitely use on here. On is the preposition we tend to use when referring to written things in these contexts. For example:

Open your books and read the text on page 27.

On this page, read the sentence on line 5.

This carries over to your situation:

The values are swapped on lines 3-5.

The code appears on those lines. If you were referring to the actual execution of the program instead of the written text of it, you might instead say something like

The values are swapped when lines 3-5 are executed.

But I think swapped on works just fine.

  • Note that we'd say "see the text on page 27" and "see listing 27.1", but not "See the code on listing 27.1, " right ? Commented Sep 12, 2013 at 2:42
  • 2
    I agree that your examples are all good English, but I think there might be a little room for personal variation here. I think that, depending on how I'm thinking of it, I might say (for example) "The values are swapped in lines 3-5." (For what it's worth, I too am a native speaker, and I've been a programmer all my life.)
    – user230
    Commented Sep 12, 2013 at 5:17
  • 1
    @snailboat Oh! The question was edited to ask if in was appropriate after I first read it; I only noticed on vs at. You're quite right, in could work as well. Silly of me to not notice the edit!
    – WendiKidd
    Commented Sep 12, 2013 at 13:04

It depends what you really mean. As a programmer myself, I see you're doing the temp swap. So the correct coding answer would be:

Swap the values at lines 3 - 5

Better would be:

Swap the value a with b, as shown on lines 3 through 5.

This is the same as

Swap the values (like they are shown) at lines 3 through 5.

  • 2
    I disagree with use of at with more than one line number at a time. Of the offered choices, in is most correct; however, it would be better to do it without a preposition: "Lines 3-5 swap the two values". Commented Sep 11, 2013 at 23:52
  • 2
    yes, your rendition "Lines 3-5 swap the two..." is even better, unless you need to emphasize a and b for some context reason. Yes, I've seen "in" used a fair amount in textbooks too, but "at" lines 3-5 is also common, and not incorrect because it refers to a block of lines as one unit, e.g. the code is folded at lines 20-30, which is a shortened version of "code is folded [starting] at lines ...". So I propose my rendition is correct as it would fully read: "The swap of values starts at line 3 and goes through line 5." Since it's really only 3 lines, such a longer version is verbose. Commented Sep 12, 2013 at 0:00
  • @ jwpat7 consider also the common idiom: "See the xyz code in listing 4.1" which is an entire block of code. Then the author might drill down into specifics: "In listing 4.1, the routine at lines 10 - 20 show how xyz does..." So In Listing at line(s). In Lines would not work well there. This probably comes from something being at an address as opposed to something being in an address @iensen - I hope it's now more obvious that all three of these work, in/on/at, but it's more a style question. You could also say, as jwpat7 suggests, "Swap the values [shown] in lines 3-5." (cont...) Commented Sep 12, 2013 at 2:05
  • (...) the important thing is to be consistent. If it's really important, have a native speaker review it if possible. In any case, we would understand what you mean if you use in/on/at. Commented Sep 12, 2013 at 2:06
  • 1
    @HowardPautz I'm a programmer and a native speaker as well, and I'd use on here, not at. "Open your books and read the text on page 27." "On this page, read the sentence on line 5." "The values are swapped on lines 3-5."
    – WendiKidd
    Commented Sep 12, 2013 at 2:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .