Please enable JavaScript.
Coggle requires JavaScript to display documents.
2.2 Programming Techniques (Operators (Always produce a boolean result…
2.2 Programming Techniques
Data Types
Boolean
Value either 1 (TRUE) or 0 (FALSE)
Default value = FALSE
Stores two-state values eg TRUE/FALSE, YES/NO
Example: DIM selected AS BOOLEAN = FALSE
Character
Example: DIM initial AS CHAR = "A"
Example: DIM space AS CHAR =""
eg letter, number as text, symbol, white space
Used to store a single character
String
Default value =NULL (nothing)
Example: hexColour AS STIRNG = "#A7D2BC"
Used to store a collection of Chars (up to 2 billion)
Real Numbers(Single,Double, Float)
Store BIG numbers
Default value = 0
Positive or Negative
Example: DIM pi AS DOUBLE = 3.14159265359
Used to store decimal numbers
Example: DIM weight AS SINGLE =76.3
Integer
Positive or Negative
Default Value = 0
Whole Number
Example: DIM counter AS INTEGER = 0
Variables
You must declare a variable before you use it: Give it a unique name,,,, Give it a data type,,,Set an initial value
Example: DIM myName AS STRING = "BOB"
Creating a variable creates a memory location where the value can be stored
The value of the variable can change during the program eg,, number of likes of a post
Used when you want your program to remember something
Constants
Use UPPER CASE for constant names
MUST be given a value when declared
Value can NOT change
Example: CONST VAT = 0.20
Are just like variables except..
Less memory intensive, easier to maintain code
Casting
print(ageStr) // output "15""
DIM ageStr AS STRING= INPUT("Enter your age")
print(ageStr
3) // output"151515"*
Convert from one data type to another
print(init(ageStr)
3) //output "45"*
Operators
Always produce a boolean result (true/false)
Arithmetic operators
Comparison operators require 2 operands
= , - , / ,
*
Example: DIM luckynumber = 7,,,, print(luckynumber) //output 7
Boolean Operators
You must always assign a value of the correct data type
AND- all comparisons must be TRUE to return TRUE
Assignment operators (=) is used to change the value of a variable
OR - at least one comparison must be TRUE to return TRUE
NOT - True returns False and False returns TRUE