Mapa mental
Programming Basics
Conteúdo do mapa
Programming Basics
Data Types
- Programming languages have Five Main Data Types
- Each data types is allocated to a different amount of memory
- Using the correct data types makes code more memory more efficient, robust (hard to break) and predictable
- Casting is used to change the Data Type
- Languages have functions that let you manually convert between data types - this is known as casting. This can be done using the int() / float() / bool() / str() commands
- int("1")
- Converts the string "1" to the integer 1
- float(1)
- Converts the integer 1 to the float 1.0
- bool(1)
- Converts the integer 1 to the Boolean value True
- str(True)
- Converts the Boolean value True to the string "True"
- int("1")
- It's important to realise that the integer 1, the real 1.0 and the strings "1" and "1.0" are all different
- You can also find the ASCII number of characters and vice versa using ASC() and CHR() functions
- ASC("b")
- Converts the character "b" into its ASCII number 98
- CHR(98)
- Converts the ASCII number 98 into its equivalent character "b"
- ASC("b")
- Using the Correct data types for different variables
Strings
- Strings are written inside Quotation Marks
- Strings can be joined together to form new strings - this is called concatenation. It's often done using + operator
- Strings are usually written inside double quotation marks ", but sometimes single quotes are used '.
- Programs let you Manipulate Strings in a variety of ways
- Characters in a string are usually numbered starting at zero
- x.upper
- Changes all characters in string x to upper case
- HELLO
- Changes all characters in string x to upper case
- x.lower
- Changes all characters in string x to lower case
- hello
- Changes all characters in string x to lower case
- x.length
- Returns the number of characters in string x
- 5
- Returns the number of characters in string x
- x[i]
- Extracts the character position I from string x
- x[1] = e
- Extracts the character position I from string x
- x.subString(a,b)
- Extracts a string starting at position a with length b from string x
- x.subString(3,2) = lo
- Extracts a string starting at position a with length b from string x
- Example - An electricity company generates a customer's 7 character username from:
- 1. the first 3 letters of their town as uppercase letters
- 2. the customer's age when they sign up (2 digits)
- 3. the first letter and last letters of the customer's surname as lowercase letters
- 2. the customer's age when they sign up (2 digits)
- 1. the first 3 letters of their town as uppercase letters
- Strings are a data type made up of characters
- Strings are written inside Quotation Marks
Program Flow
- IF statements usually have an IF-THEN-ELSE structure
- IF statements allow you to check if a condition is true or false, and carry out different actions depending on the outcome. You can think about them as a flow diagram.
- If there is nothing for the program to do when the condition is false, leave out the ELSE part.
- Nested IF statements allow multiple outputs
- More complex IF statements can be made by putting one IF statement inside another one - this type of selection statement is called a nested IF statement.
- Nested IF statements allow you to check more conditions once you've established that the previous condition is true.
- IF-ELSEIF statements can also be used to check multiple conditions. They are different from nested IF statements as they only check more conditions if the previous condition is false
- IF statements usually have an IF-THEN-ELSE structure
Informações
- Descrição
- Mapa Mental sobre Programming Basics, criado por Paul Lawrence em 06-06-2019.
- Criado por
- Paul Lawrence
- Visualizações
- 0
- Avaliação