📦 Variables and Data Types
Master variables and data types in iPseudo - the foundation of all programming!
🎯 What are Variables?
Variables are containers that store data. Think of them as labeled boxes where you can put values and retrieve them later.
pseudocode
Algorithm VariableBasics var name = "Alice" # A box labeled "name" containing "Alice" var age = 25 # A box labeled "age" containing 25 var score = 98.5 # A box labeled "score" containing 98.5 Print name # Look inside the "name" box Print age # Look inside the "age" box Print score # Look inside the "score" box Endalgorithm
🔤 Variable Declaration Styles
iPseudo offers three ways to declare variables:
Style 1: Traditional var
Keyword
Algorithm TraditionalStyle var studentName = "Bob" var studentAge = 20 var studentGPA = 3.75 var isEnrolled = true Print studentName, "-", "Age:", studentAge Endalgorithm
Style 2: Variable
Keyword
Algorithm VariableKeyword Variable studentName = "Bob" Variable studentAge = 20 Variable studentGPA = 3.75 Print studentName, "-", "Age:", studentAge Endalgorithm
Style 3: Declare As
Type System
Algorithm TypedDeclaration Declare studentName As String Declare studentAge As Integer Declare studentGPA As Float # Assign values later Set "Bob" To studentName Set 20 To studentAge Set 3.75 To studentGPA Print studentName, "-", "Age:", studentAge Endalgorithm
📊 Data Types in Detail
1. Integer (Whole Numbers)
Algorithm IntegerExamples Declare age As Integer Declare studentCount As Integer Declare temperature As Integer Set 25 To age Set 150 To studentCount Set -5 To temperature Print "Age:", age Print "Students:", studentCount Print "Temperature:", temperature Endalgorithm
2. String (Text)
Algorithm StringExamples Declare firstName As String Declare lastName As String Set "John" To firstName Set "Doe" To lastName # String concatenation var fullName = firstName + " " + lastName Print "Full name:", fullName Endalgorithm
3. Boolean (True/False)
Algorithm BooleanExamples Declare isStudent As Boolean Declare hasLicense As Boolean Set true To isStudent Set false To hasLicense Print "Is student:", isStudent Print "Has license:", hasLicense Endalgorithm
📋 Data Types Reference
Type | Values | Example |
---|---|---|
Integer |
Whole numbers | 42 , -10 |
Float |
Decimals | 3.14 , -2.5 |
Number |
Any number | 42 , 3.14 |
String |
Text | "Hello" |
Boolean |
true/false | true , false |
Char |
Single character | 'A' |
💡 Best Practices
- Initialize variables when you declare them
- Use descriptive names that explain the purpose
- Choose appropriate types for your data
- Be consistent with your syntax style
- Group related variables together
- Comment complex variable relationships
🎯 Practice Exercises
Try These:
- Create a program that demonstrates each data type
- Build a temperature converter using Float variables
- Make a calculator with proper variable types