@@ -18,7 +18,10 @@ <h2>Basic Declarations and Assignment</h2>
18
18
var yetAnotherNum: Float = 4.2;
19
19
let truth: Bool = false
20
20
var emptyString: String
21
- var first, second, third: String</ pre >
21
+ var first, second, third: String
22
+
23
+
24
+ </ pre >
22
25
</ div >
23
26
< div class ="col-md-4 ">
24
27
< pre class ="example ">
@@ -28,16 +31,47 @@ <h2>Basic Declarations and Assignment</h2>
28
31
var yetAnotherNum = 4.2;
29
32
var truth = false;
30
33
var emptyString;
31
- var first, second, third;</ pre >
34
+ var first, second, third;
35
+
36
+
37
+ </ pre >
38
+ </ div >
39
+ </ div >
40
+ < div class ="row ">
41
+ < div class ="col-md-4 ">
42
+ < h2 > Basic Operators</ h2 >
43
+ < p >
44
+ There is full support for mathematical and logical operators. For math
45
+ operations, parentheses will be included in the JS output only if they have
46
+ significance for the order of operations.
47
+ </ p >
48
+ </ div >
49
+ < div class ="col-md-4 ">
50
+ < pre class ="example ">
51
+ var answer = (5 * 6) / 4 - (-1 + 4.2) % 2
52
+ var m = ++answer;
53
+ var n = m--;
54
+ var n += answer
55
+ var b = true && !false || true
56
+ </ pre >
57
+ </ div >
58
+ < div class ="col-md-4 ">
59
+ < pre class ="example ">
60
+ var answer = 5 * 6 / 4 - (-1 + 4.2) % 2;
61
+ var m = ++answer;
62
+ var n = --m;
63
+ var n += answer
64
+ var b = true && !false || true
65
+ </ pre >
32
66
</ div >
33
67
</ div >
34
68
< div class ="row ">
35
69
< div class ="col-md-4 ">
36
- < h2 > Dictionaries and Arrays </ h2 >
70
+ < h2 > Arrays and Dictionaries </ h2 >
37
71
< p >
38
72
Swift arrays are converted to JS arrays, while dictionaries are converted to object
39
73
literals. Values are accessed via subscript lookup. There is comprehensive support for
40
- anested collections. ShiftJS does not yet support sets.
74
+ nested collections. ShiftJS does not yet support sets.
41
75
</ p >
42
76
</ div >
43
77
< div class ="col-md-4 ">
@@ -63,165 +97,77 @@ <h2>Dictionaries and Arrays</h2>
63
97
};</ pre >
64
98
</ div >
65
99
</ div >
66
- < div class ="row ">
67
- < div class ="col-md-4 ">
68
- < h2 > String Interpolation and Concatenation</ h2 >
69
- < p > There is full support for string concatenation and interpolation.</ p >
70
- </ div >
71
- < div class ="col-md-4 ">
72
- < pre class ="example ">
73
- var name = "Sam";
74
- var n = "Hi my name is " + name + ".";
75
- var planet = "Earth";
76
- let o = "Hello \(planet)!";
77
- var p = "\(100 - 99), 2, 3"</ pre >
78
- </ div >
79
- < div class ="col-md-4 ">
80
- < pre class ="example ">
81
- var name = "Sam";
82
- var n = "Hi my name is " + name + ".";
83
- var planet = 'Earth';
84
- var o = 'Hello ' + planet + '!';
85
- var p = '' + 100 - 99 + ', 2, 3';</ pre >
86
- </ div >
87
- </ div >
88
- < div class ="row ">
89
- < div class ="col-md-4 ">
90
- < h2 > Tuples</ h2 >
91
- < p >
92
- Tuples are converted to object literals. If element names are not provided,
93
- they are assigned numeric keys, indexed from zero, based on their order in the
94
- tuple. There is no support yet for tuples containing nested collections
95
- </ p >
96
- </ div >
97
- < div class ="col-md-4 ">
98
- < pre class ="example ">
99
- var error = (404, "not found")
100
- let http = (status: 200, desc: "OK")</ pre >
101
- </ div >
102
- < div class ="col-md-4 ">
103
- < pre class ="example ">
104
- var error = {0: 404, 1: 'not found'};
105
- var http = {status: 200, desc: 'OK'};</ pre >
106
- </ div >
107
- </ div >
108
- < div class ="row ">
109
- < div class ="col-md-4 ">
110
- < h2 > Mathematical and Logical Operators</ h2 >
111
- < p >
112
- There is full support for mathematical and logical operators. For math
113
- operations, parentheses will be included in the JS output only if they have
114
- significance for the order of operations.
115
- </ p >
116
- </ div >
117
- < div class ="col-md-4 ">
118
- < pre class ="example ">
119
- var answer = (5 * 6) / 4 - (-1 + 4.2) % 2
120
- var a = 1; var m = ++a; var n = --m;</ pre >
121
- </ div >
122
- < div class ="col-md-4 ">
123
- < pre class ="example ">
124
- var answer = 5 * 6 / 4 - (-1 + 4.2) % 2;
125
- var a = 1; var m = ++a; var n = --m;</ pre >
126
- </ div >
127
- </ div >
128
100
< div class ="row ">
129
101
< div class ="col-md-4 ">
130
102
< h2 > Control Flow</ h2 >
131
103
< p >
132
- Tuples are converted to object literals. If element names are not provided,
133
- they are assigned numeric keys, indexed from zero, based on their order in the
134
- tuple. There is no support yet for tuples containing nested collections
104
+ ShiftJS offers broad support if...else statements, for/for-in loops, and while/repeat-while
105
+ loops with optional parentheses. ShiftJS does not fully support block scope or switch statements.
135
106
</ p >
136
107
</ div >
137
108
< div class ="col-md-4 ">
138
109
< pre class ="example ">
139
- var gameInProgress = false;
140
- var score = 0;
141
- var typeOfScore = ""
142
- var PAT = "";
143
- while gameInProgress {
144
- if (typeOfScore != "") {
145
- if typeOfScore == "TD" {
146
- score += 6
147
- } else if typeOfScore == "PAT" {
148
- if PAT == "TD" {
149
- score += 2
150
- } else {
151
- score += 1
152
- }
153
- } else if (typeOfScore == "FG") {
154
- score += 3
110
+ for var i = 1; i < = 100; i++ {
111
+ if (i % 3 == 0) {
112
+ if i % 5 == 0 {
113
+ print("FizzBuzz")
155
114
} else {
156
- score += 2;
115
+ print("Fizz")
157
116
}
158
- typeOfScore = ""
117
+ } else if (i % 5) == 0 {
118
+ print("Buzz")
119
+ } else {
120
+ print(i)
159
121
}
160
- }</ pre >
161
- </ div >
162
- < div class ="col-md-4 ">
163
- < pre class ="example ">
164
- var gameInProgress = false;
165
- var score = 0;
166
- var typeOfScore = '';
167
- var PAT = '';
168
- while (gameInProgress) {
169
- if (typeOfScore != '') {
170
- if (typeOfScore == 'TD') {
171
- score += 6;
172
- } else if (typeOfScore == 'PAT') {
173
- if (PAT == 'TD') {
174
- score += 2;
175
- } else {
176
- score += 1;
177
- }
178
- } else if (typeOfScore == 'FG') {
179
- score += 3;
180
- } else {
181
- score += 2;
182
- }
183
- typeOfScore = '';
122
+ }
123
+ var foods = ["ham", "cheese"];
124
+ for food in foods {
125
+ print("Eats \(food).");
126
+ }
127
+ var num = 0;
128
+ while (num++ < 10 ) {
129
+ if (num % 2 == 0) {
130
+ print( "even");
131
+ } else {
132
+ print("odd");
184
133
}
185
- }</ pre >
186
- </ div >
187
- </ div >
188
- < div class ="row ">
189
- < div class ="col-md-4 ">
190
- < h2 > For-In Loops</ h2 >
191
- < p > There is full support for-in loops</ p >
134
+ }
135
+ repeat {
136
+ print("Countdown: \(num)")
137
+ } while --num > 0
138
+ print("Blast off!")</ pre >
192
139
</ div >
193
140
< div class ="col-md-4 ">
194
141
< pre class ="example ">
195
- let interestingNumbers = [
196
- "Prime": [2, 3, 5, 7, 11, 13],
197
- "Fibonacci": [1, 1, 2, 3, 5, 8],
198
- "Square": [1, 4, 9, 16, 25],
199
- ]
200
- var largest = 0
201
- for (kind, numbers) in interestingNumbers {
202
- for number in numbers {
203
- if number > largest {
204
- largest = number
142
+ for (var i = 1; i < = 100; i++) {
143
+ if (i % 3 == 0) {
144
+ if (i % 5 == 0) {
145
+ console.log('FizzBuzz');
146
+ } else {
147
+ console.log('Fizz');
205
148
}
149
+ } else if (i % 5 == 0) {
150
+ console.log('Buzz');
151
+ } else {
152
+ console.log(i);
206
153
}
207
- }</ pre >
208
- </ div >
209
- < div class ="col-md-4 ">
210
- < pre class ="example ">
211
- var interestingNumbers = {
212
- 'Prime': [2, 3, 5, 7, 11, 13],
213
- 'Fibonacci': [1, 1, 2, 3, 5, 8],
214
- 'Square': [1, 4, 9, 16, 25]
215
- };
216
- var largest = 0;
217
- for (var kind in interestingNumbers) {
218
- var numbers = interestingNumbers[kind];
219
- for (var number in numbers) {
220
- if (number > largest) {
221
- largest = number;
222
- }
154
+ }
155
+ var foods = ['ham', 'cheese'];
156
+ for (var food in foods) {
157
+ console.log('Eats ' + food + '.');
158
+ }
159
+ var num = 0;
160
+ while (num++ < 10 ) {
161
+ if (num % 2 == 0) {
162
+ console.log( 'even');
163
+ } else {
164
+ console.log('odd');
223
165
}
224
- }</ pre >
166
+ }
167
+ do {
168
+ console.log('Countdown: ' + num + '');
169
+ } while (--num > 0);
170
+ console.log('Blast off!');</ pre >
225
171
</ div >
226
172
</ div >
227
173
< div class ="row ">
@@ -268,4 +214,26 @@ <h2>Functions</h2>
268
214
}</ pre >
269
215
</ div >
270
216
</ div >
217
+ < div class ="row ">
218
+ < div class ="col-md-4 ">
219
+ < h2 > String Interpolation and Concatenation</ h2 >
220
+ < p > There is full support for string concatenation and interpolation.</ p >
221
+ </ div >
222
+ < div class ="col-md-4 ">
223
+ < pre class ="example ">
224
+ var name = "Sam";
225
+ var n = "Hi my name is " + name + ".";
226
+ var planet = "Earth";
227
+ let o = "Hello \(planet)!";
228
+ var p = "\(100 - 99), 2, 3"</ pre >
229
+ </ div >
230
+ < div class ="col-md-4 ">
231
+ < pre class ="example ">
232
+ var name = "Sam";
233
+ var n = "Hi my name is " + name + ".";
234
+ var planet = 'Earth';
235
+ var o = 'Hello ' + planet + '!';
236
+ var p = '' + 100 - 99 + ', 2, 3';</ pre >
237
+ </ div >
238
+ </ div >
271
239
</ div >
0 commit comments