Skip to content
Open

C# #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CSahrp/break.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class BREAK
{
public BREAK()
{
const bool flag = true;
Console.WriteLine("Hello");
if (flag) break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break must be used inside the loop, otherwise it won't compile and don't make sense.

Console.WriteLine("World");
}
}
10 changes: 10 additions & 0 deletions CSahrp/continue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class BREAK
{
public BREAK()
{
const bool flag = true;
Console.WriteLine("Hello");
if (flag) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue must be used inside the loop, otherwise it won't compile and don't make sense.

Console.WriteLine("World");
}
}
11 changes: 11 additions & 0 deletions CSahrp/doWhile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class WHILE
{
public WHILE()
{
int i = 0;
do
{
Console.WriteLine(i++);
} while (i < 10);
}
}
10 changes: 10 additions & 0 deletions CSahrp/for.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class FOR
{
public FOR()
{
for (let i = 0; i < 10; i++)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let is used for LINQ not for simple variable initialization, use var instead.

{
Console.WriteLine(log(i));
}
}
}
9 changes: 9 additions & 0 deletions CSahrp/forEach.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class FOREACH
{
public FOREACH()
{
const int a = { 7, 10, 1, 5, 2 };
foreach (int i in b)
Console.WriteLine(i);
}
}
26 changes: 26 additions & 0 deletions CSahrp/goto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class GOTO
{
public GOTO()
{
Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large");
Console.Write("Please enter your selection: ");
string s = Console.ReadLine();
int n = int.Parse(s);
int cost = 0;
switch (n)
{
case 1:
cost += 25;
break;
case 2:
cost += 25;
goto case 1;
case 3:
cost += 50;
goto case 1;
default:
Console.WriteLine("Invalid selection.");
break;
}
}
}
11 changes: 11 additions & 0 deletions CSahrp/while.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class WHILE
{
public WHILE()
{
int a = 0;
while (a < 10)
{
Console.WriteLine(a++);
}
}
}