-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.nv
More file actions
138 lines (101 loc) · 2.05 KB
/
test.nv
File metadata and controls
138 lines (101 loc) · 2.05 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
x:num = 3
show x
y:num = x + 7
show y
show y - x
show 2 * 3 + 4
show 2 + 3 * 4
show 10 / 2 - 1
show 10 - 2 / 2
name:string = "Nova"
show name
show "Hello, " + name
show "hello" + " " + "world"
if x > 2 start
show "x is greater than 2"
end
if y == 10 start
show "y is 10"
end else
show "y is not 10"
end
if x > y start
show "x is greater than y"
end else
show "x is not greater than y"
end
fun:num add a:num b:num start
return a + b
end
result:num = add a:3 b:4
show result
fun:num factorial n:num start
if n == 0 start
return 1
end
return n * factorial n:(n - 1)
end
show factorial n:5
fun:string greet name:string start
return "Hello, " + name
end
show greet name:"Nova"
if 1 != 2 start
show "1 != 2 is true"
end
if 2 >= 2 start
show "2 >= 2 is true"
end
if 1 <= 2 start
show "1 <= 2 is true"
show "hello"
end
is_active:bool = true
show is_active
if is_active start
show "is_active is true"
end
show 1 > 2
akram:num = 0
while akram < 3 start
show akram
akram = akram + 1
end
// New float and char tests
pi:float = 3.14
show pi
radius:float = 2.0
area:float = pi * radius
show area
grade:char = 'A'
show grade
initial:char = 'J'
show initial
sum_float:float = 10.5 + 2.3
show sum_float
diff_float:float = 10.0 - 3.5
show diff_float
product_float:float = 2.5 * 4.0
show product_float
div_float:float = 10.0 / 2.5
show div_float
num_to_float:float = 5
show num_to_float
// float_to_num:num = 7.8 // Error: cannot convert to num
// show float_to_num
// char_to_num:num = 'B' // Error: undefined variable 'char_to_num'
// show char_to_char
// num_to_char:char = 67 // Error: cannot convert to char
// show num_to_char
if pi > 3.0 start
show "Pi is greater than 3.0"
end
// if grade == 'A' start
// show "Grade is A"
// end // Error: comparison can only be performed on numbers or floats.
show 10 / 0
fun:num multiply a:num b:num c:num = 1 start
return a * b * c
end
show multiply a:2 b:3 // c should default to 1
show multiply a:2 b:3 c:4 // c is explicitly 4