|
1 |
| -function loops() { |
| 1 | +function whileLoop() { |
| 2 | + if (doLoopCalled) { |
| 3 | + var statement = "while ("; |
| 4 | + statement += getCondition(1); |
| 5 | + statement += ");\n"; |
| 6 | + // add statement to program textarea |
| 7 | + programTextArea.executeEdits("", [ |
| 8 | + { |
| 9 | + range: { |
| 10 | + startLineNumber: programTextArea.getPosition().lineNumber, |
| 11 | + startColumn: programTextArea.getPosition().column, |
| 12 | + endLineNumber: programTextArea.getPosition().lineNumber, |
| 13 | + endColumn: programTextArea.getPosition().column, |
| 14 | + }, |
| 15 | + text: statement, |
| 16 | + forceMoveMarkers: true, |
| 17 | + }, |
| 18 | + ]); |
| 19 | + doLoopCalled=0; |
2 | 20 |
|
3 |
| - var statement = 'while ('; //statement variable contains the entire while-statement including the condition |
4 |
| - statement += getCondition(1); // get condition and append it to the statement |
5 |
| - statement += ') {\n\n'; // add closing paranthesis and braces to while loop |
| 21 | + autoIndent(); //implement indentation for closing brace |
| 22 | + } else { |
| 23 | + var statement = "while ("; //statement variable contains the entire while-statement including the condition |
| 24 | + statement += getCondition(1); // get condition and append it to the statement |
| 25 | + statement += ") {\n\n"; // add closing parenthesis and braces to while loop |
| 26 | + |
| 27 | + // add statement to program textarea |
| 28 | + programTextArea.executeEdits("", [ |
| 29 | + { |
| 30 | + range: { |
| 31 | + startLineNumber: programTextArea.getPosition().lineNumber, |
| 32 | + startColumn: programTextArea.getPosition().column, |
| 33 | + endLineNumber: programTextArea.getPosition().lineNumber, |
| 34 | + endColumn: programTextArea.getPosition().column, |
| 35 | + }, |
| 36 | + text: statement, |
| 37 | + forceMoveMarkers: true, |
| 38 | + }, |
| 39 | + ]); |
| 40 | + |
| 41 | + autoIndent(); //implement indentation for closing brace |
| 42 | + |
| 43 | + //add closing brace to textarea |
| 44 | + programTextArea.executeEdits("", [ |
| 45 | + { |
| 46 | + range: { |
| 47 | + startLineNumber: programTextArea.getPosition().lineNumber, |
| 48 | + startColumn: programTextArea.getPosition().column, |
| 49 | + endLineNumber: programTextArea.getPosition().lineNumber, |
| 50 | + endColumn: programTextArea.getPosition().column, |
| 51 | + }, |
| 52 | + text: "}", |
| 53 | + forceMoveMarkers: true, |
| 54 | + }, |
| 55 | + ]); |
| 56 | + // set cursor to between the braces |
| 57 | + programTextArea.setPosition({ |
| 58 | + lineNumber: programTextArea.getPosition().lineNumber - 1, |
| 59 | + column: programTextArea.getPosition().columnNumber + 2, |
| 60 | + }); |
| 61 | + |
| 62 | + indent++; // added new braces, hence increment indent |
| 63 | + autoIndent(); //call function to implement auto indent |
| 64 | + } |
| 65 | + |
| 66 | + programTextArea.focus(); // focus cursor on textarea |
| 67 | +} |
| 68 | + |
| 69 | +//do loop |
| 70 | +function doLoop() { |
| 71 | + var statement = "do {\n\n"; //Add parenthesis and opening brace to do loop |
6 | 72 |
|
7 | 73 | // add statement to program textarea
|
8 |
| - programTextArea.executeEdits("", [{ |
9 |
| - range: { |
| 74 | + programTextArea.executeEdits("", [ |
| 75 | + { |
| 76 | + range: { |
10 | 77 | startLineNumber: programTextArea.getPosition().lineNumber,
|
11 | 78 | startColumn: programTextArea.getPosition().column,
|
12 | 79 | endLineNumber: programTextArea.getPosition().lineNumber,
|
13 |
| - endColumn: programTextArea.getPosition().column |
| 80 | + endColumn: programTextArea.getPosition().column, |
| 81 | + }, |
| 82 | + text: statement, |
| 83 | + forceMoveMarkers: true, |
14 | 84 | },
|
15 |
| - text: statement, |
16 |
| - forceMoveMarkers: true |
17 |
| - }]); |
| 85 | + ]); |
18 | 86 |
|
19 |
| - autoIndent() //implement indentation for closing brace |
| 87 | + autoIndent(); //implement indentation for closing brace |
20 | 88 |
|
21 | 89 | //add closing brace to textarea
|
22 |
| - programTextArea.executeEdits("", [{ |
23 |
| - range: { |
24 |
| - startLineNumber: programTextArea.getPosition().lineNumber, |
25 |
| - startColumn: programTextArea.getPosition().column, |
26 |
| - endLineNumber: programTextArea.getPosition().lineNumber, |
27 |
| - endColumn: programTextArea.getPosition().column |
28 |
| - }, |
29 |
| - text: '}', |
30 |
| - forceMoveMarkers: true |
31 |
| - }]); |
| 90 | + programTextArea.executeEdits("", [ |
| 91 | + { |
| 92 | + range: { |
| 93 | + startLineNumber: programTextArea.getPosition().lineNumber, |
| 94 | + startColumn: programTextArea.getPosition().column, |
| 95 | + endLineNumber: programTextArea.getPosition().lineNumber, |
| 96 | + endColumn: programTextArea.getPosition().column, |
| 97 | + }, |
| 98 | + text: "}", |
| 99 | + forceMoveMarkers: true, |
| 100 | + }, |
| 101 | + ]); |
32 | 102 |
|
33 | 103 | // set cursor to between the braces
|
34 |
| - programTextArea.setPosition({lineNumber: programTextArea.getPosition().lineNumber - 1, column: programTextArea.getPosition().columnNumber + 2}) |
| 104 | + programTextArea.setPosition({ |
| 105 | + lineNumber: programTextArea.getPosition().lineNumber - 1, |
| 106 | + column: programTextArea.getPosition().columnNumber + 2, |
| 107 | + }); |
35 | 108 |
|
36 |
| - indent++ // added new braces, hence increment indent |
37 |
| - autoIndent() //call function to implement auto indent |
| 109 | + indent++; // added new braces, hence increment indent |
| 110 | + autoIndent(); //call function to implement auto indent |
38 | 111 |
|
39 | 112 | programTextArea.focus(); // focus cursor on textarea
|
40 | 113 | }
|
| 114 | + |
| 115 | +//IMPLEMENT FOR LOOP FUNCTIONALITY |
| 116 | +function forLoop() {} |
0 commit comments