AnyCompiler

Operators and Control Flow

if and else work as you'd expect from any C-family language — a condition in parentheses, followed by a block.

for and while

A classic for loop declares an index, a condition, and an increment, all in its header. while simply repeats while its condition is true, with no built-in index at all.

using System;

class Program {
    static void Main() {
        int score = 73;
        if (score >= 60) {
            Console.WriteLine("pass");
        } else {
            Console.WriteLine("fail");
        }
        for (int i = 1; i <= 3; i++) {
            Console.Write(i + " ");
        }
        Console.WriteLine();
    }
}
Output
pass
1 2 3 

Next: methods — defining methods, parameters, return types, and method overloading.

Practice exercise

Set a variable score of type int to 73. Print "pass" if score is 60 or above, otherwise print "fail".