Skip to content

Examples

Techcraft7 edited this page Jan 12, 2021 · 10 revisions

7Sharp examples

Here are some examples of 7Sharp code to help people learn the language!

Hello, World!

write("Hello, World!");

Say hello to user (with variable)

writeraw("Enter name: ");
name = read();
write("Hello, " + name + "!");

Say hello to user (no variable)

writeraw("Enter name: ");
write("Hello, " + read() + "!");

Count from 1 to 10

loop (10) {
  write(getLoopIndex() + 1);
}

Nesting getLoopIndex(n = 0)

loop(5) {
    loop(5) {
        write("i = " + getLoopIndex(1) + " j = " + getLoopIndex());
    }
}

Fibonacci

a = double(0);
b = double(1);
c = double(0);
loop (50) {
  c = a + b;
  b = a;
  a = c;
  write(c);
}

Print grid of every color combination

loop (16) {
    bgColor(getLoopIndex());
    loop (16) {
        writeraw("X");
        fgColor(getLoopIndex());
    }
    write("");
}
resetColor();

Output of program ^

Clone this wiki locally