← Back to Scala Course | Chapter 1: Setup & Basics | Lesson 3 of 8

The Scala REPL

The Scala REPL is a chat window where you type one line and get an answer straight away. It is like a scratch pad for trying out ideas without writing a whole program.

In this page:

  1. The Scala REPL
Syntax
scala
$ scala
scala> expression

The Scala REPL

The Scala REPL (Read-Eval-Print Loop), started by typing scala with no arguments, lets you type expressions and see results immediately, each annotated with its inferred type.

It's the fastest way to experiment with small snippets before writing a full program. Every top-level expression you enter is automatically evaluated and printed.

Note: Type :quit (or press Ctrl+D) to exit the Scala REPL.

Example: The Scala REPL

markup
object Main extends App {
  // Simulating what you'd see typing directly into the REPL:
  val result = 2 + 2
  println(s"2 + 2 = $result")
  println("In the REPL, typing '2 + 2' alone would print 'val res0: Int = 4'")
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Typing a multi-line class into the REPL and pressing Enter after each line, when the REPL runs each input immediately unless you use :paste.
  2. Expecting REPL variables to persist after quitting, when they are lost after :quit.
  3. Confusing scala for the REPL with scala file.scala for running a file, and being surprised by the REPL prompt.
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.