Question: I am a beginner of the scala. many concepts aren't clear for me.
I want to ask that if the foreach can get (or control) the array parameter ?

for example:

```
val array = Array.ofDim[Double](2,6)

```

I can use for to control the array's parameter, like

```
for( i <- 0 until 2){
   for(j <- 0 until 6){
      .........      }}

```

I can use **i,j** control and get the parameter. Is "**foreach**" can do that??

(I know foreach can do things without the parameter, but I just want to ask if it can get 
 the array parameter?)

thank you :)

Answer: 
I'm not exactly sure what you're asking. If you're asking how to loop over the full array item-by-item, then you can do that without nesting `for` comprehensions. This will print the contents of your 2D array:

```
for (row <- array; col <- row) println(col)

```

If you're asking how to loop over all the *indices* of the array (I think maybe that's what you mean when you say *parameter*), then you can use the `indices` property:

```
for (i <- array.indices; j <- array(i).indices) println(array(i)(j))

```

---

If you're just trying to do `indexOf` across a 2D array, you can probably just reuse the solution for *[indexOf for 2D Vector in Scala](https://stackoverflow.com/questions/16411244/indexof-for-2d-vector-in-scala)*. This is how I'd adapt it to your code:

```
val array = Array.tabulate(2,6)(_*6+_)
val searchValue = 8
val indices: Option[(Int, Int)] = 
  (for {
     i <- array.indices
     j <- array(i).indices
     if (array(i)(j) == searchValue)
   } yield (i, j)).headOption

```

If none of the values match, you'll get `indices = None`. In this case there is a match, so you get `indices = Some((1,2))`, because `8` is at `array(1)(2)`.

*(Note: Unlike `indexOf`, using a for comprehension does not short-circuit as soon as it finds the solution. If you make the index ranges lazy by calling `.iterator`, `.view` or `.toStream` then you'll get the expected short-circuiting behavior.)*
U can use the function [ indexOf(elem: T): Int ] that will return the position

[Scala Array](http://www.scala-lang.org/api/current/index.html#scala.Array)