Skip to content

Commit cf65a8a

Browse files
committed
should be while instead of for
1 parent ecadbad commit cf65a8a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Scalatron/doc/tutorial/tutorial_20_bot_10.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ loop to do an efficient traversal:
330330
def offsetToNearest(c: Char) = {
331331
var nearestPosOpt : Option[XY] = None
332332
var nearestDistance = Double.MaxValue
333-
for(i <- 0 until cells.length) {
333+
var i = 0
334+
while(i < cells.length) {
334335
if(c == cells(i)) {
335336
val pos = absPosFromIndex(i)
336337
val distanceToCenter = pos.distanceTo(center)
@@ -339,6 +340,7 @@ loop to do an efficient traversal:
339340
nearestPosOpt = Some(pos - center)
340341
}
341342
}
343+
i += 1
342344
}
343345
nearestPosOpt
344346
}

Scalatron/doc/tutorial/tutorial_20_bot_10_step_4C.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ case class View(cells: String) {
2222
def offsetToNearest(c: Char) = {
2323
var nearestPosOpt : Option[XY] = None
2424
var nearestDistance = Double.MaxValue
25-
for(i <- 0 until cells.length) {
25+
var i = 0
26+
while(i < cells.length) {
2627
if(c == cells(i)) {
2728
val pos = absPosFromIndex(i)
2829
val distanceToCenter = pos.distanceTo(center)
@@ -31,6 +32,7 @@ case class View(cells: String) {
3132
nearestPosOpt = Some(pos - center)
3233
}
3334
}
35+
i += 1
3436
}
3537
nearestPosOpt
3638
}

0 commit comments

Comments
 (0)