mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-17 12:13:55 +00:00
Initial commit
This commit is contained in:
parent
ca7684985d
commit
49bdd4dda1
60 changed files with 1527 additions and 30 deletions
47
vscode/Chapter03/IterationStatements/Program.cs
Normal file
47
vscode/Chapter03/IterationStatements/Program.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// Looping with the while statement
|
||||
|
||||
int x = 0;
|
||||
|
||||
while (x < 10)
|
||||
{
|
||||
WriteLine(x);
|
||||
x++;
|
||||
}
|
||||
|
||||
// Looping with the do statement
|
||||
|
||||
string? password;
|
||||
int attempts = 0;
|
||||
|
||||
do
|
||||
{
|
||||
attempts++;
|
||||
Write("Enter your password: ");
|
||||
password = ReadLine();
|
||||
}
|
||||
while ((password != "Pa$$w0rd") & (attempts < 10));
|
||||
|
||||
if (attempts < 10)
|
||||
{
|
||||
WriteLine("Correct!");
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLine("You have used 10 attempts!");
|
||||
}
|
||||
|
||||
// Looping with the for statement
|
||||
|
||||
for (int y = 1; y <= 10; y++)
|
||||
{
|
||||
WriteLine(y);
|
||||
}
|
||||
|
||||
// Looping with the foreach statement
|
||||
|
||||
string[] names = { "Adam", "Barry", "Charlie" };
|
||||
|
||||
foreach (string name in names)
|
||||
{
|
||||
WriteLine($"{name} has {name.Length} characters.");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue