Difference between revisions of "W1206 Expression Evaluation vs Printing"

From Coder Merlin
Line 23: Line 23:
   5><br/>
   5><br/>
}}
}}
Now, let's copy exactly the same contents into a file named main.swift and then execute that file.


== Key Concepts ==
== Key Concepts ==

Revision as of 17:26, 17 November 2019

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Epson MX-80
Nixdorf PC 8810-25

Prerequisites[edit]

Introduction[edit]

Printing refers to sending a stream of data, most often text but sometimes binary data as well, to an output device. Frequently this device is simply the console. The console refers to the input and output devices used to interact with a computer. It's usually comprised of a screen and keyboard, and sometimes a type of pointing device.

Printing is important not only for interacting with humans, but with other computing systems. For example, you've already had a lot of experience in interacting with the  Merlin Mission Manager  through print statements.

Expression Evaluation[edit]

As we learned earlier, there are many different types of expressions, including integer, floating point, and Boolean. Expressions, when evaluated, yield a specific value. But, the evaluation of an expression is very different from printing. This can sometimes be confusing, because when using an environment such as a REPL, the results of expressions are automatically printed to the console. In a real program, however, this does not occur. Let's examine a few examples.

Printing vs Expression Evaluation[edit]

Let's first have a look at what happens inside the REPL.

Welcome to Swift.

Type :help for assistance.

  1> func multiplyByTwo(number:Int) -> Int {

  2. return number * 2

  3. }

  4> multiplyByTwo(number:3)

  $R0: Int = 6

  5>

Now, let's copy exactly the same contents into a file named main.swift and then execute that file.

Key Concepts[edit]

Exercises[edit]

References[edit]