for_loop.carbon 765 B

12345678910111213141516171819202122232425262728293031
  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. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. fn Main() -> i32 {
  8. var ar: [i32; 4] = (0, 1, 2, 3);
  9. var count: i32 = 0;
  10. for (x: i32 in ar) {
  11. Print("HALLO WELT {0}", x);
  12. count = count + 1;
  13. }
  14. for (x: i32 in ar) {
  15. Print("HALLO WELT {0}", x);
  16. count = count + 1;
  17. }
  18. return count;
  19. }
  20. // CHECK:STDOUT: HALLO WELT 0
  21. // CHECK:STDOUT: HALLO WELT 1
  22. // CHECK:STDOUT: HALLO WELT 2
  23. // CHECK:STDOUT: HALLO WELT 3
  24. // CHECK:STDOUT: HALLO WELT 0
  25. // CHECK:STDOUT: HALLO WELT 1
  26. // CHECK:STDOUT: HALLO WELT 2
  27. // CHECK:STDOUT: HALLO WELT 3
  28. // CHECK:STDOUT: result: 8