0% found this document useful (0 votes)
23 views

Grade 9 - Computer Logic-Formulation-Variables

The document discusses variable types and naming conventions in logic formulation and game design. It defines variables as pieces of information that can be stored, retrieved, and processed. Variables must be declared before use and initialized to have an initial value. The main variable types are string, integer, float, and boolean. String stores text, integer stores whole numbers, float stores numbers with decimals, and boolean stores true/false values. Variables must follow naming rules where names start with letters or underscore and use camelCase. Operators like addition and concatenation can be used depending on the variable type.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Grade 9 - Computer Logic-Formulation-Variables

The document discusses variable types and naming conventions in logic formulation and game design. It defines variables as pieces of information that can be stored, retrieved, and processed. Variables must be declared before use and initialized to have an initial value. The main variable types are string, integer, float, and boolean. String stores text, integer stores whole numbers, float stores numbers with decimals, and boolean stores true/false values. Variables must follow naming rules where names start with letters or underscore and use camelCase. Operators like addition and concatenation can be used depending on the variable type.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

LOGIC

FORMULATION
GAME DESIGN AND DEVELOPMENT
OBJECTIVES

At the end of the lesson, the learners will:


● Understand Variable types
● Understand the Data Types
● Explain the importance of variables for
solving problems
● Understand the importance of proper naming
convention
TABLE OF CONTENTS

DECLARING NAMING
A VARIABLE RULES

DATA TYPES VARIABLE


ASSIGNMENT
01
DECLARING A VARIABLE
Logic Formulation
VARIABLE
● Used to store piece of information
to be retrieved, used, and process
later.
● Must be declared before it can be
used.
● Can be initialized to have an initial
value.
VARIABLE
VARIABLE NAME VALUE

string name = “Juan Dela Cruz”


ASSIGNMENT
DATA TYPE

Declaring a Variable
02
DATA TYPES
Logic Formulation
DATA TYPES
string Collection of characters that is used represent a text.

Whole number (no decimal part). Can be negative or positive.


int (integer)
(e.g. Age)

float Number with decimal part (e.g. Money)

bool (boolean) Logical data type that can have only the values true or false.

Collection of fixed number of components (elements),


Array
wherein all components should have the same data type.
EXAMPLES

string name = michael

string name = “michael”

string name = “michael123”

string name = “michael123” barb


EXAMPLES
int number = 50
int number = “50”
int number = -50
int number = 50 + 10
int number = 50.00
EXAMPLES
float number = 25.0
float number = “25.0”
float number = -25.00
float number = 25.00 + 10.0
float number = 25
INT and FLOAT

10

int number number = 10


(Variable)
INT and FLOAT

10 20

int number number = 20


(Variable)
INT and FLOAT

10 20 (15+15)

int number number = 30


(Variable)
STRING

“mike”

string name name = mike


(Variable)
STRING

“mike” “barb”

string name name = barb


(Variable)
STRING

“mike” “barb” “mike” + “barb”

string name name = mikebarb


(Variable)
( + ) – concatenator, used to
concatenate or combine string values
STRING

“mike” “barb” “mike” - “barb”

string name name =


(Variable)
***Invalid. We can not use - for string
value or any other operator
ARRAY

“a”

int Array
(Variable)
***Invalid, our Array is integer (int).
ARRAY

1 3 5 8 9 10

0 1 2 3 4 5
int Array
Items = 6
(Variable)
length = 5
ARRAY

1 3 5 8 9 10

0 1 2 3 4 5
int Array
Items = 6
(Variable)
length = 5 length = no. of items - 1
BOOLEAN OPERATOR

Using the OR operator, we can create a compound expression


OR
that is true when either of two conditions are true.

Using the AND operator, we can create a compound expression


AND
that is true only when both of the conditions are true.

Using the NOT operator, we can reverse the truth value of an


NOT
entire expression, from true to false or false to true.
BOOLEAN OPERATOR
LOGICAL OPERATOR
== Exactly equal to 12 == 12 (true), “one” == “one” (true), 10 == 10.00 (false)

< Less than 3 < 5 (true), 5 < 3 (false), 4 < 4 (false), 3 < 3.5 (invalid)

> Greater than 3 > 5 (false), 5 > 3 (true), 4 > 4 (false), 3 > 3.5 (invalid)

<= Less than equal to 3 <= 5 (true), 5 <= 3 (false), 4 <= 4 (true), 3 <= 3.5 (invalid)

>= Greater than equal to 3 >= 5 (false), 5 >= 3 (true), 4 >= 4 (true), 3 <= 3.5 (invalid)

3 != 5 (true), 5 != 3 (true), 4 != 4 (false), 3 != 3.5 (invalid)


!= Not equal to
03
NAMING RULES
Logic Formulation
NAMING RULES
1 2 3

Variable name No spaces and Naming a


must begin special variable name
with letter of characters follows the of
the alphabet the
or an (_) camelCase.
underscore.
EXAMPLES

name last_name
_name last_name_

1name _last_name_

*name
EXAMPLES

Camel Case camelCase

Full Name fullName

License license
Date of Birth dateOfBirth
EXAMPLES
EXAMPLES
04
VARIABLE ASSIGNMENT
Logic Formulation
VARIABLE ASSIGNMENT

● Not all variable stay the same. A variable can


change anytime.
● Not all variable stay the same. A variable can
change anytime.
● We use the equal sign ( = ) operator to assign a
value to a variable.
● Assignment happens inside a process of
variable initialization.
VARIABLE ASSIGNMENT
IMPORTANT NOTE:
( = ) operator is different from mathematics. Equals
does not mean they are equal. Equal means you want to
update the left-hand side value using the right hand
side value.
● Age = 20 means age value is now 20. It
doesn't mean they are equal.
● Age == 20 means we are checking if both sides
are equal.
EXAMPLES
20 = 20 invalid
20 == 20 valid true
20 == “twenty” valid false
“twenty” == “twenty” valid true
year = 2022 year is now 2022
THANK YOU,
GOD BLESS!

You might also like