Lecture 9 (Tychonievich) - Scope

Lecture Date: Monday, February 2

A variable is like a box, which can fit only one type of value.

Variables either store a primitive type or where to find a non-primitive type.

Curly braces create a scope, in which variables live; when the closing curly brace appears, the variables created inside it disappear too. Actions performed still happened.

Curly braces may be preceded by a control construct with the form keyword ( expression ) { ... }.

  • if(someBoolean) { ... } skips the code in the braces if someBoolean is false.
  • while(someBoolean) { ... } repeats the code in the braces until someBoolean is false.

NEVER put a ; between a ) and a {.

From lecture: