Core C#

If-Elseif-Elseif-Else Statements

This C# program demonstrates how to use the if-elseif-elseif-else statement.

Program.cs

using System;

namespace XoaX {
    class Program {
        static void Main(string[] args) {
            string sString = "";
            for (int i = 0; i < 40; ++i) {
                char c = ' ';
                // Change every character at an even index to '*'
                if ((i % 3) == 0) {
                    c = '*';
                } else if ((i % 2) == 0) {
                    // Set the remaining even characters to "&"
                    c = '&';
                } else if ((i % 5) == 0) {
                    // Set the remaining evry fifth characters to "|"
                    c = '|';
                } else {
                    // Set the rest to "-"
                    c = '-';
                }
                sString += c;
            }
            Console.WriteLine(sString);
        }
    }
}
 

Output

*-&*&|*-&*&-*-&*&-*-&*&-*|&*&-*-&*&|*-&*
Press any key to continue . . .
 
 

© 2007–2024 XoaX.net LLC. All rights reserved.