Answers.Body: <p>This is a community-editable wiki. Feel free to edit it.</p>
  <hr />
  <h1>Example of Three Languages and Only Two Compilers</h1>
  <p>Suppose that someone is writing code for a text-adventure video-game where they want to translate a large number of simple sentences from natural language into python, with an intermediate language in between.</p>
  <p>You might assume that there are 3 compilers for 3 languages, but there are one 2 compilers.</p>
  <blockquote>
  <ol>
  <li><p>A language of short simple (not complex or compound) alpha-numeric German sentences.</p>
  <ul>
  <li>kombinieren Mehl, Wasser, Basilikum und Knoblauch</li>
  </ul>
  </li>
  <li><p>A middle language of highly structured German verbs and nouns with order of operations specified with parentheses, square-brackets, curly-braces, etc...</p>
  <ul>
  <li>kombinieren(Mehl, Wasser, Basilikum, Knoblauch)</li>
  </ul>
  </li>
  <li><p>python.</p>
  </li>
  </ol>
  </blockquote>
  <hr />
  <h1>Example of Shelves for a Closet Full of Shoes</h1>
  <p>Imagine a large-household where rooms are given to guests or rented out to tenants.</p>
  <p>The number of shelves is different than the number of shelf-spaces on which shoes can be placed.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-25T22:27:57.937Z
Answers.LastActivityDate: 2023-05-25T22:27:57.937Z
Answers.UserDisplayName: Samuel Muldoon
Answers.Body: <p>Probably the most common out by one error is the fence-post error.</p>
  <p>In a linear fence, the number of posts is one more than the number of panels.
  It is important to know whether you are counting fence-posts or panels. And, to know which quantity you want to know. Then you can adjust.</p>
  <p>You can build a lesson around this concept, before bringing it back to programming.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-27T11:54:02.490Z
Answers.LastActivityDate: 2023-05-27T11:54:02.490Z
Answers.UserDisplayName: ctrl-alt-delor
Answers.Body: <p>I'm unclear if &quot;real world&quot; means a programming or non-programming context, but an infamous real-world example of this was following the introduction of the Julian calendar, by Julius Caesar in 46 BC.</p>
  <p>There was widespread misunderstanding about the then-new 4-year cycle of the leap day, and it was instead observed every 3 years in the pattern of 1-2-3-leap-2-3-leap-2-3-leap.</p>
  <p>This practice today is called &quot;inclusive counting&quot;, where the last year of one cycle is also considered to be first year of the next cycle, and was a more common practice at the time.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-31T12:04:40.407Z
Answers.LastActivityDate: 2023-05-31T12:04:40.407Z
Answers.UserDisplayName: Steve
Answers.Body: <p>Basically anything involving intervals, discrete and continuous.</p>
  <p>What is the distance between 1 and 10? <code>10 - 1 = 9</code>, but:</p>
  <ul>
  <li>If these are kilometer posts, it's 9 kilometers along the road.</li>
  <li>If these are buildings, there are 8 buildings between buildings 1 and 10.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-18T13:30:14.487Z
Answers.Text: So there are b-a+1 elements in integer interval [a,b]; there are b-a-1 elements in integer interval (a,b); there are b-a elements in integer interval [a,b). Programming language python decided that basic language constructs would always be expressed using intervals of form [a,b) because it makes it easier to avoid off-by-one errors. For instance, an array `a` has "length" `len(a)`, meaning that its number of elements is `len(a)`, and its elements are indexed by integer interval [0, `len(a)`); and if you write `for i in range(0, len(a))` you are iterating on this interval.
Answers.UserDisplayName: Stef
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-31T21:45:22.387Z
Answers.LastActivityDate: 2023-05-31T21:45:22.387Z
Answers.UserDisplayName: yeputons
Body: <p>A lot of teaching examples of <em>off-by-one</em> errors which educators provide to their students involve <strong>for</strong>-loops.</p>
  <p>For example, we might have the following for-loop:</p>
  <pre class="lang-cpp prettyprint-override"><code>// Array `A` contains `50` names indexed from `0` to `49`  
  //
  //     0 ... Orquil Bolouri
  //     1 ... Manuel Tobellon
  //     2 ... Kabatha Dowling
  //     3 ... Lornton Krowley
  
  Toni Toson
  // `numel(A)` returns the number of elements in array `A`   
  // `numel(A)` represents the number `50` in this context 
  
  for k from 0 to numel(A) {
      first_name = get_first_name(A); 
      print(first_name);  
  }    
  </code></pre>
  <h1>What are examples of off-by-one Error in the &quot;<em>Real World</em>&quot;?</h1>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-31T20:07:16.333Z
Comments.Text: You've asked a variety of "how do I teach X using a real-world example?" questions here. Why are you so sure you need to use so-called "real-world examples" to teach these concepts? Do we need to have a separate thread for collecting lists of "real-world" examples for each and every CS concept? As discussed at length in [this thread](https://cseducators.stackexchange.com/a/7669/9426), I suggest distinguishing "physical world" from "practical computing". Many physical world examples are not very practical metaphors in computing, even if students are familiar with them IRL.
Comments.UserDisplayName: ggorlen
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-31T20:12:51.940Z
Comments.Text: Also, since off-by-one errors generally manifest in loops and arrays, what is your motivation for needing an example outside of this domain, which represents the vast majority of the off-by-one errors students will encounter in programming?
Comments.UserDisplayName: ggorlen
Tags: <resource-request>
Title: What are some teaching examples for a lesson on off-by-one errors which do not involve a for-loop or array indexing?
ThreadText: # What are some teaching examples for a lesson on off-by-one errors which do not involve a for-loop or array indexing?
  
  (Asked by: username_0 on 2023-05-25)
  
  A lot of teaching examples of *off-by-one* errors which educators provide to their students involve **for**-loops.
  
  For example, we might have the following for-loop:
  
  ```cpp
  // Array `A` contains `50` names indexed from `0` to `49`  
  //
  //     0 ... Orquil Bolouri
  //     1 ... Manuel Tobellon
  //     2 ... Kabatha Dowling
  //     3 ... Lornton Krowley
  
  Toni Toson
  // `numel(A)` returns the number of elements in array `A`   
  // `numel(A)` represents the number `50` in this context 
  
  for k from 0 to numel(A) {
      first_name = get_first_name(A); 
      print(first_name);  
  }    
  
  ```
  
  # What are examples of off-by-one Error in the "*Real World*"?
  
  **Tags:** resource-request
  
  > **Comments:**
  > **username_1**: You've asked a variety of "how do I teach X using a real-world example?" questions here. Why are you so sure you need to use so-called "real-world examples" to teach these concepts? Do we need to have a separate thread for collecting lists of "real-world" examples for each and every CS concept? As discussed at length in [this thread](https://cseducators.stackexchange.com/a/7669/9426), I suggest distinguishing "physical world" from "practical computing". Many physical world examples are not very practical metaphors in computing, even if students are familiar with them IRL.  
  > **username_1**: Also, since off-by-one errors generally manifest in loops and arrays, what is your motivation for needing an example outside of this domain, which represents the vast majority of the off-by-one errors students will encounter in programming?  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2023-05-27. Score: 5
  
  Probably the most common out by one error is the fence-post error.
  
  In a linear fence, the number of posts is one more than the number of panels.
  It is important to know whether you are counting fence-posts or panels. And, to know which quantity you want to know. Then you can adjust.
  
  You can build a lesson around this concept, before bringing it back to programming.
  
  
  ---
  
  ### Answer by username_3 on 2023-05-31. Score: 2
  
  I'm unclear if "real world" means a programming or non-programming context, but an infamous real-world example of this was following the introduction of the Julian calendar, by Julius Caesar in 46 BC.
  
  There was widespread misunderstanding about the then-new 4-year cycle of the leap day, and it was instead observed every 3 years in the pattern of 1-2-3-leap-2-3-leap-2-3-leap.
  
  This practice today is called "inclusive counting", where the last year of one cycle is also considered to be first year of the next cycle, and was a more common practice at the time.
  
  
  ---
  
  ### Answer by username_4 on 2023-05-31. Score: 2
  
  Basically anything involving intervals, discrete and continuous.
  
  What is the distance between 1 and 10? `10 - 1 = 9`, but:
  
  * If these are kilometer posts, it's 9 kilometers along the road.
  * If these are buildings, there are 8 buildings between buildings 1 and 10.
  
  > **Comments:**
  > **username_5**: So there are b-a+1 elements in integer interval [a,b]; there are b-a-1 elements in integer interval (a,b); there are b-a elements in integer interval [a,b). Programming language python decided that basic language constructs would always be expressed using intervals of form [a,b) because it makes it easier to avoid off-by-one errors. For instance, an array `a` has "length" `len(a)`, meaning that its number of elements is `len(a)`, and its elements are indexed by integer interval [0, `len(a)`); and if you write `for i in range(0, len(a))` you are iterating on this interval.  
  
  ---
  
  ### Answer by username_0 on 2023-05-25. Score: 0
  
  This is a community-editable wiki. Feel free to edit it.
  
  ---
  
  # Example of Three Languages and Only Two Compilers
  
  Suppose that someone is writing code for a text-adventure video-game where they want to translate a large number of simple sentences from natural language into python, with an intermediate language in between.
  
  You might assume that there are 3 compilers for 3 languages, but there are one 2 compilers.
  
  > 1. A language of short simple (not complex or compound) alpha-numeric German sentences.
  >
  >    * kombinieren Mehl, Wasser, Basilikum und Knoblauch
  > 2. A middle language of highly structured German verbs and nouns with order of operations specified with parentheses, square-brackets, curly-braces, etc...
  >
  >    * kombinieren(Mehl, Wasser, Basilikum, Knoblauch)
  > 3. python.
  
  ---
  
  # Example of Shelves for a Closet Full of Shoes
  
  Imagine a large-household where rooms are given to guests or rented out to tenants.
  
  The number of shelves is different than the number of shelf-spaces on which shoes can be placed.
  
  
  ---
  
  