Home   Cover Cover Cover Cover
 

Schleifentransformation

A04.cs
using System;

class Test {
  
  static void Foo(int i) {
    Console.WriteLine(i);
  }
  
  static void Main(string[] arg) {
    //--- while
    int i = Convert.ToInt32(arg[0]);
    while (i > 0) { Foo(i); i--; }
    
    //--- do while
    i = Convert.ToInt32(arg[0]);
    if (i > 0)
      do { Foo(i); i--; } while (i > 0);
    
    //--- for
    for (i = Convert.ToInt32(arg[0]); i > 0; i--) Foo(i);
  }
  
}