Variables

Variables in Rui allow you to store and manipulate data. Rui uses implicit typing, which means you don't need to declare the type of a variable - Rui figures it out automatically.

Creating Variables

To create a variable in Rui, use the suppose keyword followed by the variable name and value:

suppose name = "Alice"
suppose age = 25
suppose isStudent = true

Rui automatically determines that:

  • name is a string
  • age is a number
  • isStudent is a boolean

Variable Naming Rules

Variable names in Rui must follow these rules:

  • Start with a letter or underscore
  • Can contain letters, numbers, and underscores
  • Are case-sensitive
  • Cannot be reserved words

Good variable names:

suppose firstName = "John"
suppose user_age = 30
suppose totalCount = 100

Invalid variable names:

suppose 123name = "invalid"  {/* Cannot start with a number */}
suppose first-name = "invalid"  {/* Cannot contain hyphens */}
suppose if = "invalid"  {/* Cannot use reserved words */}

Using Variables

You can use variables in expressions and pass them to functions:

suppose name = "Bob"
suppose age = 30

write("Hello, " + name)
write("You are " + age + " years old")

Reassigning Variables

You can change the value of a variable by assigning a new value:

suppose count = 5
write(count)  // Prints: 5

suppose count = 10
write(count)  // Prints: 10

Variable Types

Rui supports several data types:

Numbers

suppose integer = 42
suppose decimal = 3.14
suppose negative = -10

Strings

suppose greeting = "Hello"
suppose name = 'World'
suppose multiline = "This is a
multiline string"

Booleans

suppose isTrue = true
suppose isFalse = false

String Concatenation

You can combine strings using the + operator:

suppose firstName = "John"
suppose lastName = "Doe"
suppose fullName = firstName + " " + lastName
write(fullName)  // Prints: John Doe

Example Program

Here's a complete example that demonstrates variables:

{/* Store user information */}
suppose name = "Alice"
suppose age = 25
suppose city = "New York"

{/* Display the information */}
write("Name: " + name)
write("Age: " + age)
write("City: " + city)

{/* Calculate and display age next year */}
suppose nextYearAge = age + 1
write("Next year, " + name + " will be " + nextYearAge + " years old")

Next Steps

Now that you understand variables, learn about Operators to perform calculations and comparisons.