Learn to Code via Tutorials on Repl.it!

← Back to all posts
C# Dash: Level 3 - Conditionalgeist

C# Dash: Level 3 - Conditionalgeist

So how did you do in the last challenge. Well, I have an example repl at the bottom.

So were about to start level 3. This level will be IMPORTANT, so please pay attention to the stuff in the tutorial.

This tutorial will cover conditionals (loops too) and arrays.

The reader is expected to have read the last few tutorials.

Some info was retrieved from the Microsoft .NET Online C# Documentation

Words like this will appear in the glossary at the bottom.

More tutorials

Scratch Tutorials

SO LET'S GET STARTED!!!!!!!!!!!!!!!!!!!!!!!!


Conditionals are very important in all programming languages because that will make some code only execute if a certain condition is true.

If-else statements

If-else statements will activate a block of code if the conditional statement evaluates to true. If you need to evaluate multiple conditions, people generally use else if to have more than one condition. Here is a basic program if if, else if, and else:

Also, there can (obviously) be more else if statements, as many as you need.

But sometimes, they can become annoying when you need multiple conditions all for the same variable...

Switch statements

Switch statements allow you to have multiple conditions for one variable without a ton of effort.

The statement starts with switch and the variable in ()s. Then there's the brackets.

Then there's cases. A case is where you have the outputs for the condition if the variable equals a certain value.

After the case keyword and the value for the variable, there's a colon (:). Then you have the output.

In the output for each case, the code for the case must end with the following line:

One case must be default. It can appear anywhere on the list of cases, but the important part is that it acts as an else. The code will run in the default case if the value is not equal to any other value in the list of cases.

Here is the same program before, but with a switch statement.

While statement (loop)

A while statement is how you can generate a simple loop in C#. It will consist of the keyword while and then a condition in parenthesis. Then you have brackets, and of course, the code.

The code will repeat until the condition is false.


This will generate an infinite loop that just says "True". But there's more complicated loops too.

For statement (loop)

A for loop will allow you to have a local variable, a condition, and something that happens upon loop iteration completion. Those three things in ()s are separated by semicolons (;) Then, there's the brackets and code.


So that's enough about conditionals. Let's move onto arrays.


Arrays are like variables that store multiple values. This one example for the syntax of an array:

For more about arrays, click here.

Level complete!

Next level: Methods and parameters.

Coding challenge (optional)

Write a program that will ask for user input and will print all the numbers from 1-20 or from 1-100 based on user input. Use loops and if-else/switch statements.


  • Condition - An expression that evaluates to either true or false, often used to make statements that execute code if a statement is true or false.
  • Local variable - A variable that cannot be used outside of its method, for statement, or wherever it comes from.

Example for yesterday's challenge:


fixed link