Skip to content

Commit

Permalink
Off-by-one error spotted by Jason McLafferty
Browse files Browse the repository at this point in the history
  • Loading branch information
dionyziz committed Apr 29, 2013
1 parent e1da965 commit 389c83b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions index-el.php
Expand Up @@ -46,7 +46,7 @@
var M = A[ 0 ];

for ( var i = 0; i < n; ++i ) {
if ( A[ i ] > M ) {
if ( A[ i ] >= M ) {
M = A[ i ];
}
}
Expand Down Expand Up @@ -89,10 +89,10 @@
<p>Τώρα, κοιτάζοντας το σώμα του <code>for</code>, έχουμε μία εντολή εύρεσης στοιχείου πίνακα και μία σύγκριση που λαμβάνουν χώρα πάντοτε:</p>

<pre class='brush: jscript; gutter: false; toolbar: false;'>
if ( A[ i ] &gt; M ) { ...
if ( A[ i ] &gt;= M ) { ...
</pre>

<p>Αυτές είναι δύο εντολές από μόνες τους. Όμως το σώμα του <code>if</code> μπορεί να τρέξει ή μπορεί και όχι, ανάλογα με το τι τιμές έχει πραγματικά ο πίνακας. Αν συμβεί και είναι <code>A[ i ] &gt; M</code>, τότε θα τρέξουμε αυτές τις δύο επιπλέον εντολές — μία εύρεση στοιχείου πίνακα και μία ανάθεση:</p>
<p>Αυτές είναι δύο εντολές από μόνες τους. Όμως το σώμα του <code>if</code> μπορεί να τρέξει ή μπορεί και όχι, ανάλογα με το τι τιμές έχει πραγματικά ο πίνακας. Αν συμβεί και είναι <code>A[ i ] &gt;= M</code>, τότε θα τρέξουμε αυτές τις δύο επιπλέον εντολές — μία εύρεση στοιχείου πίνακα και μία ανάθεση:</p>

<pre class='brush: jscript; gutter: false; toolbar: false;'>
M = A[ i ]
Expand Down
6 changes: 3 additions & 3 deletions index-en.php
Expand Up @@ -42,7 +42,7 @@
var M = A[ 0 ];

for ( var i = 0; i &lt; n; ++i ) {
if ( A[ i ] &gt; M ) {
if ( A[ i ] &gt;= M ) {
M = A[ i ];
}
}
Expand Down Expand Up @@ -85,10 +85,10 @@
<p>Now, looking at the <code>for</code> body, we have an array lookup operation and a comparison that happen always:</p>

<pre class='brush: jscript; gutter: false; toolbar: false;'>
if ( A[ i ] &gt; M ) { ...
if ( A[ i ] &gt;= M ) { ...
</pre>

<p>That's two instructions right there. But the <code>if</code> body may run or may not run, depending on what the array values actually are. If it happens to be so that <code>A[ i ] &gt; M</code>, then we'll run these two additional instructions — an array lookup and an assignment:</p>
<p>That's two instructions right there. But the <code>if</code> body may run or may not run, depending on what the array values actually are. If it happens to be so that <code>A[ i ] &gt;= M</code>, then we'll run these two additional instructions — an array lookup and an assignment:</p>

<pre class='brush: jscript; gutter: false; toolbar: false;'>
M = A[ i ]
Expand Down
6 changes: 3 additions & 3 deletions index-es.php
Expand Up @@ -44,7 +44,7 @@
var M = A[ 0 ];

for ( var i = 0; i &lt; n; ++i ) {
if ( A[ i ] &gt; M ) {
if ( A[ i ] &gt;= M ) {
M = A[ i ];
}
}
Expand Down Expand Up @@ -87,10 +87,10 @@
<p>Ahora, si nos fijamos en el cuerpo del <code>for</code> tenemos una operación de búsqueda en array y una comparación que ocurre siempre:</p>

<pre class='brush: jscript; gutter: false; toolbar: false;'>
if ( A[ i ] &gt; M ) { ...
if ( A[ i ] &gt;= M ) { ...
</pre>

<p>Eso serían dos instrucciones. Pero el cuerpo del <code>if</code> podría correr o no correr, dependiendo de cuáles son los valores del array. Si ocurriese que <code>A[ i ] &gt; M</code>, ntonces ejecutaremos dos instrucciones adicionales – una búsqueda en array y una asignación:</p>
<p>Eso serían dos instrucciones. Pero el cuerpo del <code>if</code> podría correr o no correr, dependiendo de cuáles son los valores del array. Si ocurriese que <code>A[ i ] &gt;= M</code>, ntonces ejecutaremos dos instrucciones adicionales – una búsqueda en array y una asignación:</p>

<pre class='brush: jscript; gutter: false; toolbar: false;'>
M = A[ i ]
Expand Down
6 changes: 3 additions & 3 deletions index-mk.php
Expand Up @@ -45,7 +45,7 @@
var M = A[ 0 ];

for ( var i = 0; i &lt; n; ++i ) {
if ( A[ i ] &gt; M ) {
if ( A[ i ] &gt;= M ) {
M = A[ i ];
}
}
Expand Down Expand Up @@ -89,10 +89,10 @@
<p> Сега, гледајќи го <code>for</code> циклусот, имаме операција за пребарување на низа и споредба која се случува секогаш кога: </p>

<pre class='brush: jscript; gutter: false; toolbar: false;'>
if ( A[ i ] &gt; M ) { ...
if ( A[ i ] &gt;= M ) { ...
</pre>

<p> Тоа се две инструкции. Но кодот во if условот може да се изврши или може да не се изврши, зависно од вредностите на низата. Ако се случи да биде A <code>A[ i ] &gt; M</code>, тогаш ова ќе изврши дополнителни 2 инструкции - барање во низата и едно доделување:</p>
<p> Тоа се две инструкции. Но кодот во if условот може да се изврши или може да не се изврши, зависно од вредностите на низата. Ако се случи да биде A <code>A[ i ] &gt;= M</code>, тогаш ова ќе изврши дополнителни 2 инструкции - барање во низата и едно доделување:</p>

<pre class='brush: jscript; gutter: false; toolbar: false;'>
M = A[ i ]
Expand Down

0 comments on commit 389c83b

Please sign in to comment.