for_loop.carbon 816 B

1234567891011121314151617181920212223242526272829303132
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: HALLO WELT 0
  9. // CHECK:STDOUT: HALLO WELT 1
  10. // CHECK:STDOUT: HALLO WELT 2
  11. // CHECK:STDOUT: HALLO WELT 3
  12. // CHECK:STDOUT: HALLO WELT 0
  13. // CHECK:STDOUT: HALLO WELT 1
  14. // CHECK:STDOUT: HALLO WELT 2
  15. // CHECK:STDOUT: HALLO WELT 3
  16. // CHECK:STDOUT: result: 8
  17. package ExplorerTest api;
  18. fn Main() -> i32 {
  19. var ar: [i32; 4] = (0, 1, 2, 3);
  20. var count: i32 = 0;
  21. for (x: i32 in ar) {
  22. Print("HALLO WELT {0}", x);
  23. count = count + 1;
  24. }
  25. for (x: i32 in ar) {
  26. Print("HALLO WELT {0}", x);
  27. count = count + 1;
  28. }
  29. return count;
  30. }