0

Write a c# program to print your name 10 times on console using goto statement?

24th Dec 2016, 1:19 PM
jabar
jabar - avatar
3 Antworten
+ 3
There is in fact a goto in C#. (https://msdn.microsoft.com/en-gb/library/13940fs2.aspx) I recommend avoiding it and only using it in switches and loops when really necessary.
6th Jan 2017, 12:45 AM
Maike
+ 2
there is no command like "goto" in c#. your code gets unreadable if your working on a larger project. for your purpose a for or while loop fits best, like string name = "John Doe"; for(int i = 0; i < 10; i++) { Console.WriteLine("Hello {0}", name); }
25th Dec 2016, 9:42 AM
qobus
+ 1
using System; namespace Foobar { class Program { static int foo = 0; static void Main() { //goto version - NOT recommended bar: Console.WriteLine("You Name"); i++; if (i < 10) goto bar; //for (; ;) version - recommended for (int i = 0; i < 10; i++) Console.WriteLine("Your Name"); } } }
6th Jan 2017, 5:17 PM
Maike