D.ershane Solutions Ddili.org

The for Loop

  1. import std.stdio;
    
    void main() {
        for (int line = 0; line != 9; ++line) {
            for (int column = 0; column != 9; ++column) {
                write(line, ',', column, ' ');
            }
    
            writeln();
        }
    }
    
  2. Triangle:
    import std.stdio;
    
    void main() {
        for (int line = 0; line != 5; ++line) {
            int length = line + 1;
    
            for (int i = 0; i != length; ++i) {
                write('*');
            }
    
            writeln();
        }
    }
    

    Parallellogram:

    import std.stdio;
    
    void main() {
        for (int line = 0; line != 5; ++line) {
            for (int i = 0; i != line; ++i) {
                write(' ');
            }
    
            writeln("********");
        }
    }
    

    Can you produce the diamond pattern?

       *
      ***
     *****
    *******
     *****
      ***
       *