cara membuar for , while , dow while, for each :
1. buka visual studio
2. buka form Console Application visual #c
setelah muncul gambar diatas masukan koding/code seperti ini :
int number = 0;
Console.WriteLine("while");
while (number < 5)
{
Console.WriteLine(number);
number = number + 1;
}
Console.WriteLine("=========================================");
Console.WriteLine("For loop");
for (int i = 0; i < number; i++)
{
Console.WriteLine(i);
}
Console.WriteLine("==========================================");
Console.WriteLine("Foreach loop");
{
ArrayList list = new ArrayList();
list.Add("John Doe");
list.Add("Jane Doe");
list.Add("Someone Else");
foreach (string name in list)
Console.WriteLine(name);
}
Console.WriteLine("==========================================");
Console.WriteLine("Do while");
int[] ids = new int[] { 6, 7, 8, 10 };
int sum = 0;
int i = 0;
do
{
sum += ids[i];
i++;
} while (i < 4);
System.Console.WriteLine(sum);
Console.ReadLine();
lalu klik start, dan akan muncul form baru berwarna hitam
SELESAI:)
Tidak ada komentar:
Posting Komentar