I'm newly at Scala.
I want to run function which is wrote at my file while.scala
:
def whileLoop {
var i = 1
while(i <= 3) {
println(i)
i += 1
}
}
whileLoop
here is how it looks at REPL:
scala> scala /home/nazar/Downloads/while.scala
<console>:1: error: illegal start of simple expression
If I understood right from book. I need to specify .scala
file location and run with:
scala /path/to/file.scala
Why it fails?
Here is snippet from book:
You can run the code like this:
batate$ scala code/scala/while.scala
1
2
3
UPDATE:
I tried options :load
it works, but when I want to run another file for_loop.scala
:
def forLoop {
println( "for loop using Java-style iteration" )
for(i <- 0 until args.length) {
println(args(i))
}
}
forLoop
it fails:
scala> :load /home/nazar/Downloads/for_loop.scala
Loading /home/nazar/Downloads/for_loop.scala...
<console>:9: error: not found: value args
for(i <- 0 until args.length) {
^
<console>:8: error: not found: value forLoop
forLoop
^
scala> :load /home/nazar/Downloads/for_loop.scala hello scala
That file does not exist
How to solve this trouble?