-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsyntax.rn
executable file
·102 lines (83 loc) · 1.66 KB
/
syntax.rn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# This is a comment
# Arithmetic operators
# + - Addition
# - - Subtraction
# * - Multiplication
# / - Division
# % - Modulus
# ^ - Exponentiation
# Comparison operators
# == - Equal to
# != - Not equal to
# > - Greater than
# < - Less than
# >= - Greater than or equal to
# <= - Less than or equal to
# Logical operators
# and - Logical and
# or - Logical or
# not - Logical not
# Assignment operators (Development)
# = - Assign
# += - Add and assign
# -= - Subtract and assign
# *= - Multiply and assign
# /= - Divide and assign
# %= - Modulus and assign
# ^= - Exponentiation and assign
# Variable definition
var a = 10
var b = 20
print(a + b) # 30
var c = "Hello"
var d = "World"
print(c + " " + d) # Hello World
# Conditional statement
if a > b {
print("a is greater than b")
} elif a < b {
print("a is less than b")
} else {
print("a is equal to b")
}
# For loop
var x = 9 # Multiplication table of 9
for i = 1 to 11 {
print(str(x) + " X " + str(i) + " = " + str(x * i))
}
# While loop
while x > 0 {
print(x)
x -= 1
}
# Function definition
fun add(a, b) {
return a + b
}
print(add(10, 20)) # 30
# Anonymous function
var sub = fun (a, b) {
return a - b
}
print(sub(20, 10)) # 10
# Single line function
fun mul(a, b) -> a * b
print(mul(10, 20)) # 200
# Class definition
class Person {
# Constructor
fun __constructor__(name, age) {
this.name = name
this.age = age
}
fun get_name() {
return this.name
}
fun get_age() {
return this.age
}
}
# Use a class
var person = Person("Almas", 21)
var details = "Name is : " + person.get_name() + ", Age : " + str(person.get_age())
print(details)