Vi har en vektor:
int[] numbers = new int[] {1,23,43,4,2435,2456,4};
Loopa genom hela vektorn och skriv ut värdena med en:
1. for-loop
2. foreach
3. while-loop
4. do-while-loop
det två första är ju fixat:
5. namespace ConsoleApplication3
6. {
7. class Program
8. {
9. static void Main(string[] args)
10. {
11. int[] numbers = new int[] { 1, 23, 43, 4, 2435, 2456, 4 };
12.
13. for (int i = 0; i <numbers.Length; i++)
14. {
15. Console.WriteLine(numbers[i]);
16.
17. }
18.
19.
20. }
21.
22. }
23. }
24. namespace ConsoleApplication3
25. {
26. class Program
27. {
28. static void Main(string[] args)
29. {
30. int[] numbers = new int[] { 1, 23, 43, 4, 2435, 2456, 4 };
31.
32. foreach(int number in numbers)
33. { Console.WriteLine(number);
34. }
35.
36. }
37.
38.
39. }
40.
41. }
42.
Men det andra två?
3. while-loop
4. do-while-loop