Variable assignment in Soul
=
name = "Alice"; age = 30; isStudent = true;
count = 10; count += 5; // count = count + 5 → 15 count -= 3; // count = count - 3 → 12 count *= 2; // count = count * 2 → 24 count /= 4; // count = count / 4 → 6 count %= 3; // count = count % 3 → 0
// List assignment numbers = [1, 2, 3]; numbers[0] = 10; // First element becomes 10 // Map assignment user = { name: "Bob", age: 25 }; user["email"] = "bob@example.com"; user.age = 26; // Dot notation also works
// Simple assignments x = 5; y = x + 10; // Object property assignment person = {}; person.name = "Charlie"; person["occupation"] = "Developer"; // Nested assignments data = { users: [] }; data.users[0] = { id: 1, name: "Dave" };
if ((result = calculateValue())) { println("Result: " + result); } while ((line = readNextLine())) { processLine(line); }
userCount
c
// Good userCount = 0; userName = "guest"; isLoggedIn = false; // Avoid x = 5; x = "now a string"; // Type changed
Was this page helpful?