Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | // This code is not run directly. It needs to be compiled to dex code. |
| 6 | // 'controlflow.dex' is what is run. |
| 7 | |
| 8 | package controlflow; |
| 9 | |
| 10 | public class ControlFlow { |
| 11 | |
| 12 | public static void simpleIf(boolean b) { |
| 13 | String s = "Hep!"; |
| 14 | if (b) { |
| 15 | s = "Fisk"; |
| 16 | } else { |
| 17 | s = "Hest"; |
| 18 | } |
| 19 | System.out.println(s); |
| 20 | } |
| 21 | |
| 22 | public static void simpleIfMoreValues(boolean b) { |
| 23 | int i = 0; |
| 24 | double d = 0.0; |
| 25 | String s = "Hep!"; |
| 26 | if (b) { |
| 27 | i = 1; |
| 28 | d = 1.1; |
| 29 | s = "Fisk"; |
| 30 | b = false; |
| 31 | } else { |
| 32 | i = 2; |
| 33 | d = 2.2; |
| 34 | s = "Hest"; |
| 35 | } |
| 36 | if (i == 1) { |
| 37 | b = true; |
| 38 | } |
| 39 | System.out.println(s + " " + i + " " + d + " " + b); |
| 40 | } |
| 41 | |
| 42 | public static void simpleIfFallthrough(boolean b) { |
| 43 | String s = "Hep!"; |
| 44 | if (b) { |
| 45 | s = "Fisk"; |
| 46 | } |
| 47 | System.out.println(s); |
| 48 | } |
| 49 | |
| 50 | public static void sequenceOfIfs(int i) { |
| 51 | if (i < 10) { |
| 52 | System.out.println("10"); |
| 53 | } |
| 54 | if (i < 5) { |
| 55 | System.out.println("5"); |
| 56 | } |
| 57 | if (i < 2) { |
| 58 | System.out.println("2"); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | public static void nestedIfs(int i) { |
| 63 | if (i < 10) { |
| 64 | System.out.println("10"); |
| 65 | if (i < 5) { |
| 66 | System.out.println("5"); |
| 67 | if (i < 2) { |
| 68 | System.out.println("2"); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | public static void simpleLoop(int count) { |
| 75 | System.out.println("simpleLoop"); |
| 76 | for (int i = 0; i < count; i++) { |
| 77 | System.out.println("count: " + i); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public static void main(String[] args) { |
| 82 | simpleIf(true); |
| 83 | simpleIf(false); |
| 84 | simpleIfMoreValues(true); |
| 85 | simpleIfMoreValues(false); |
| 86 | simpleIfFallthrough(true); |
| 87 | simpleIfFallthrough(false); |
| 88 | sequenceOfIfs(10); |
| 89 | sequenceOfIfs(9); |
| 90 | sequenceOfIfs(4); |
| 91 | sequenceOfIfs(1); |
| 92 | nestedIfs(10); |
| 93 | nestedIfs(9); |
| 94 | nestedIfs(4); |
| 95 | nestedIfs(1); |
| 96 | simpleLoop(0); |
| 97 | simpleLoop(1); |
| 98 | simpleLoop(10); |
| 99 | } |
| 100 | } |