class Person {
name = "Unknown";
age = 0;
_temp = null;
Person(this, name, age = 18) {
this.name = name;
this.age = age;
}
~Person(this) {
print("Person destroyed:", this.name);
}
greet(this) {
print("Hello, I am", this.name, "and I am", this.age, "years old");
}
setAge(this, newAge) {
this.age = newAge;
}
}
person = new Person("Alice", 25);
person.greet();
person2 = new Person("Bob");
person2.greet();
person.setAge(30);
print("Alice new age:", person.age);
x = 10;
y = 20;
print("Sum:", x + y);
print("Product:", x * y);
str1 = "Hello";
str2 = " World";
result = str1 + str2;
print("Concatenation:", result);
str1 += "!";
print("After +=:", str1);
count = 0;
while (count < 3) {
print("Count:", count);
count++;
}
for (i = 0; i < 3; i++) {
print("For loop i:", i);
}
val = null || 5;
print("Default value:", val);
val2 = 10 || 5;
print("Existing value:", val2);
if (1) {
print("Truthy: 1 is true");
}
if (0) {
print("This should not print");
} else {
print("Falsy: 0 is false");
}
arr = {1, 2, 3, 4, 5};
print("Array element 0:", arr[0]);
print("Array element 2:", arr[2]);
arr[1] = 10;
print("Modified array element 1:", arr[1]);
testStr = "hello world";
print("Substr:", testStr.substr(0, 5));
print("Count 'o':", testStr.count("o"));
parts = testStr.split(" ");
print("Split result count:", len(parts));
numStr = "42";
num = int(numStr);
print("Converted to int:", num);
converted = str(123);
print("Converted to str:", converted);
class Counter {
value = 0;
Counter(this, start = 0) {
this.value = start;
}
increment(this) {
this.value++;
}
decrement(this) {
this.value--;
}
getValue(this) {
return this.value;
}
}
counter = new Counter(5);
print("Counter initial:", counter.getValue());
counter.increment();
counter.increment();
print("Counter after 2 increments:", counter.getValue());
counter.decrement();
print("Counter after decrement:", counter.getValue());
a = 5;
b = 5;
if (a == b) {
print("a equals b");
}
if (a != 10) {
print("a is not 10");
}
if (a < 10 && b < 10) {
print("Both a and b are less than 10");
}
if (a > 10 || b < 10) {
print("Either a > 10 or b < 10");
}
print("All tests completed successfully");