1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15declare function print(arg:any):void; 16let F : number[] = [0, 1, 2] 17let G : number[] = [0, 1, 2] 18 19function tryLoopOpt(f: number[], v : number): void { 20 let idx = 1 - 1; 21 let ret = f[idx]; 22 for (let i = 0; i < f.length; ++i) { 23 f[i] += 1; 24 f[i] += v; 25 } 26 print(ret); 27 print(f[idx]); 28 print(f[idx + 1]); 29} 30 31tryLoopOpt(F, <number><Object>'a'); 32 33function tryMergeOpt(g: number[], v : number): void { 34 let idx = 1 - 1; 35 let ret = g[idx]; 36 if (g[idx] < 10) { 37 g[idx] -= 10; 38 } else { 39 v++; 40 } 41 print(ret + v); 42 print(g[idx]); 43} 44 45tryMergeOpt(G, <number><Object>'b');