Loops Lists and Arrays in c#

This commit is contained in:
Geir Okkenhaug Jerstad 2024-11-18 12:56:05 +01:00
parent 2c097039f6
commit 06a6529881
12 changed files with 243 additions and 0 deletions

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
namespace Loops
{
class Program
{
static void Main(string[] args)
{
WhileLoop();
//DoWhileLoop();
forEachLoop();
ForLoop();
}
// while
static void WhileLoop()
{
bool shouldRun = true;
int i = 0;
while (shouldRun == true)
{
if (i >= 19)
{
shouldRun = false;
}
Console.WriteLine($"Hei verdi: {i}");
i++;
}
}
//do while
static void DoWhileLoop()
{
do
{
Console.WriteLine("Doing while...");
} while (true);
}
// foreach
static void forEachLoop()
{
int[] numberArray = {1,2,3,4,5,6,7,8,9,10};
foreach (var number in numberArray)
{
Console.WriteLine(number);
}
}
// For loop
static void ForLoop()
{
for (int i = 0; i <= 20; i++)
{
Console.WriteLine($"For loop...{i}");
}
}
}
}