вход по аккаунту

код для вставкиСкачать
 The words used to describe different aspects of
programming have significant meaning.
 For example…
 Variables are called variables because the value
that they store is “variable” over time.
 Assignment, to assign means to transfer, so when
we assign a value to a variable we transfer or
“assign” a value to a variable.
Constants and Code Readability
 Can you spot something that keeps appearing in
the code?
What does the number 7 represent?
What if the board was 12 x 12?
What are Constants?
 The important difference between a constant and a variable is that
when the value of a constant is set at declaration, that value cannot be
 Consider the two sections of code…
Declaring Constants
1. We don’t use camel case in our constant names we
use capitals.
Const DAYS_OF_WEEK as Integer = 7
Const NOTES_IN_OCTAVE as Integer = 8
2. Also notice that we must set the value of the
constant as soon as we declare it…
Const MY_CONSTANT As String = "hello"
Const DAYS_OF_WEEK as Integer = 7
Const NOTES_IN_OCTAVE as Integer = 8
Consider the Following Code
 The value of a constant is fixed, which means it cannot be the target of
an assignment operation.
 That’s why it is called a constant and not a variable.
A Constant in use
Compare the Following
Compare the following…
We know that BOARD_SIZE is a constant due to
the capitalisation
The value we are using here is the size of the
board (not numbers of eggs!)
Again – What if we make the board 12 x 12?
Пожаловаться на содержимое документа