Skip to content

Commit

Permalink
Add string and floating point examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Sep 19, 2024
1 parent 80f2a32 commit 070f77c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/expression-equality/expression_equality.bal
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,20 @@ public function main() {
// Since values of simple types do not have a storage identity,
// `===` will evaluate to `true` because the values are the same.
io:println(a === b);

decimal c = 1.0;
decimal d = 1.00;
// `===` and `==`` are the same for simple values except for floating point types.
// The output will be `true` because the values are equal.
io:println(c == d);
// The output will be `false` because `c` and `d` are distinct values with different precision.
io:println(c === d);

string s1 = "Hello";
string s2 = "Hello";

// The string type is a sequence type, not a simple type,
// but `==` and `===` still behave the same for string comparisons
io:println(s1 == s2);
io:println(s1 === s2);
}
4 changes: 4 additions & 0 deletions examples/expression-equality/expression_equality.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ true
false
true
true
true
false
true
true

0 comments on commit 070f77c

Please sign in to comment.