1

This is a code that is written in Scala :

for (i <- 0 until 10) {
  if (i > 0) {
    val new = theta(i * 5)
  }
  // using variable new

  val theta = DenseVector.zeros[Int]((i + 1) * 10)
  // doing operations on theta
}

every iteration has own variables and order of variables can't change because between them doing some operations.

when i running this code it shows this error:

Wrong forward reference

how can i resolve this problem?

yanana
  • 2,241
  • 2
  • 18
  • 28
AHAD
  • 239
  • 4
  • 16

1 Answers1

1

Replace theta before if expression by making theta method.

def theta(i: Int) = DenseVector.zeros[Int]((i + 1) * 10)
for (i <- 0 until 10) {
  if (i > 0) {
    val new = theta(i * 5)
  }
  // doing operations on theta
}
yanana
  • 2,241
  • 2
  • 18
  • 28
  • Thank you @yanana , but when i want to assign values to every element of this vector, it shows " Too many argument for method theta (Int)" – AHAD Jul 25 '15 at 14:08
  • How do you assign values to the vector? – yanana Jul 25 '15 at 18:19