Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functions Used to write code only once Can use parameters.

Similar presentations


Presentation on theme: "Functions Used to write code only once Can use parameters."— Presentation transcript:

1 Functions Used to write code only once Can use parameters

2 using System; namespace Demo01 { class Program static void Main(string[] args) string name = "world"; int year = 2017; for (int i = 0; i < 10; i++) PrintYear(name, i + year); } private static void PrintYear(string name, int year) Console.WriteLine("Hello " + name + ", the year is " + year);

3 string name = "Loek"; Console.WriteLine(name); name = "Antje"; int year = 2017; for (int i = 0; i < 10; i++) { // everything that happens here, happens 10 times Console.WriteLine("Hello " + name + " the current year is " + (year + i)); }

4 Condition

5 int startYear = 2010; for (int i = 0; i < 10; i++) { int year = startYear + i; if (year == 2017) Console.WriteLine(year + " is the current year"); } else Console.WriteLine(year + " is NOT the current year");

6 int startYear = 2010; for (int i = 0; i < 10; i++) { int year = startYear + i; if (year == 2017) Console.WriteLine(year + " is the current year"); } else if (year < 2017) Console.WriteLine(year + " is before the current year"); else Console.WriteLine(year + " is after the current year");

7 int startYear = 2010; for (int i = 2010; i < 2020; i++) { int year = startYear + i; if (year == 2017) Console.WriteLine(year + " is the current year"); } else if (year < 2017) Console.WriteLine(year + " is before the current year"); else Console.WriteLine(year + " is after the current year");

8 Methods

9 Console.WriteLine("+======================================+");
Console.WriteLine("Hello, my name is: LOEK"); Console.WriteLine(""); Console.WriteLine("Hello, my name is: LEO"); Console.WriteLine("Hello, my name is: PIET");

10 static void Main(string[] args)
{ Console.WriteLine("Atendee list"); Console.WriteLine("––––––––––––––––––––––"); Console.WriteLine(""); PrintName("Karl"); PrintName("Petra"); } static void PrintName(string name) Console.WriteLine(name);


Download ppt "Functions Used to write code only once Can use parameters."

Similar presentations


Ads by Google