8 Replies - 19198 Views - Last Post: 15 April 2014 - 07:53 AM

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Challenge: The 10 Ways to Loops (Easy)

Post icon  Posted 25 March 2012 - 08:51 PM

Challenge: The 10 Ways To Loop

Challenge:

From my experimentation and exploration of the language I believe that are only 10 ways different ways in VB.Net to perform looping and iteration.

See if you can discover those 10 ways.
Each one must output to the Console Window the numbers 1 to 10, each on a separate line.

Place each way you find into it's own method (Sub) and call it from Sub Main

Put your submissions inside of spoiler and code tags.

Note: (.net 3.5 used)
Bonus: Find ways not on my list, if there is any.

This post has been edited by AdamSpeight2008: 26 March 2012 - 01:28 PM


Is This A Good Question/Topic? 1
  • +

Replies To: Challenge: The 10 Ways to Loops (Easy)

#2 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1949
  • View blog
  • Posts: 4,048
  • Joined: 11-December 07

Re: Challenge: The 10 Ways to Loops (Easy)

Posted 26 March 2012 - 05:30 PM

Here are 12 methods. It depends on how different they have to be to be different. Some of these are pretty similar. You reduce this to about 5 if you wanted to. Also, replace write for writeline to print the numbers on separate lines.

I was disappointed that there was no GOSUB in VB. Also, I couldn't find out how to convert a variable's contents to a line label, if it's even possible. That would allow for a strange method of looping.

Adam, how does this compare with your list?

Spoiler

Was This Post Helpful? 1
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: Challenge: The 10 Ways to Loops (Easy)

Posted 26 March 2012 - 07:44 PM

cfoley: You use For .. Loop twice, but that offset by the two additional ones of using errors and exceptions.

This post has been edited by AdamSpeight2008: 26 March 2012 - 07:45 PM

Was This Post Helpful? 0
  • +
  • -

#4 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1949
  • View blog
  • Posts: 4,048
  • Joined: 11-December 07

Re: Challenge: The 10 Ways to Loops (Easy)

Posted 27 March 2012 - 03:36 AM

Does that mean you have one that I didn't get?
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4462
  • View blog
  • Posts: 7,776
  • Joined: 08-June 10

Re: Challenge: The 10 Ways to Loops (Easy)

Posted 27 March 2012 - 06:18 AM

I guess this is sorta cheating, because you can use basically any of the LINQ methods for this:

Spoiler


I haven't kept up with the differences between VB.NET and C#. I wanted to use an iterator method, but apparently I'll have to wait for that. I could have sworn I had seen it, but it must have been async ctp code.
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Challenge: The 10 Ways to Loops (Easy)

Posted 28 March 2012 - 08:36 AM

cfoley covered a lot of them but I guess you could get as obscure as a timer for a "Timed Loop"
Spoiler


This of course would not loop in the sense that the loop has to finish before processing the remaining code but would loop WHILE still processing any remaining code.

This post has been edited by CharlieMay: 28 March 2012 - 08:38 AM

Was This Post Helpful? 0
  • +
  • -

#7 demausdauth  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 638
  • Joined: 03-February 10

Re: Challenge: The 10 Ways to Loops (Easy)

Posted 02 April 2012 - 07:11 PM

Forgot the Untils


Public Sub DoUntil()

     Dim n As Integer = 0
     Do Until n = 11          
          n += 1
          Console.WriteLine("{0}", n)
     Loop
End Sub

Public Sub LoopUntil()
     Dim n As Integer = 1

     Do
          Console.WriteLine("{0}",n)
          n += 1
     Loop Until n = 10
End Sub



Was This Post Helpful? 0
  • +
  • -

#8 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Re: Challenge: The 10 Ways to Loops (Easy)

Posted 06 April 2012 - 07:00 PM

Spoiler

Was This Post Helpful? 0
  • +
  • -

#9 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Challenge: The 10 Ways to Loops (Easy)

Posted 15 April 2014 - 07:53 AM

well check this one
Spoiler

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1