We are excited to announce that the ASP.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

## 2 replies

Last post Nov 04, 2011 04:23 PM by bionictiki

• bionictiki

Member

1 Points

3 Posts

### for loop position rotation

Does anyone know how to create this sequence using a for loop and/or nested for loops? I'm having trouble. Thanks

 1 2 3 4 5 6 7 8 9 10 11 2 3 4 5 6 7 8 9 10 11 1 3 4 5 6 7 8 9 10 11 1 2 4 5 6 7 8 9 10 11 1 2 3 5 6 7 8 9 10 11 1 2 3 4 6 7 8 9 10 11 1 2 3 4 5 7 8 9 10 11 1 2 3 4 5 6 8 9 10 11 1 2 3 4 5 6 7 9 10 11 1 2 3 4 5 6 7 8 10 11 1 2 3 4 5 6 7 8 9 11 1 2 3 4 5 6 7 8 9 10
• atconway

Star

12060 Points

2740 Posts

### Re: for loop position rotation

Yep here it is:

```Dim MyIntList As New List(Of Integer)

Dim x As Integer = 1
For j As Integer = 1 To 11
For i As Integer = x To 11
If (x > 1) And (i = 11) Then i = 0
If (x > 1) And (i = (x - 1)) Then Exit For
Next
x += 1
Next```

An interview or logic question by chance.  I didn't recognize a number pattern I am familiar with (which is almost none) so if that is a know pattern they may be a mathematically better way to solve this problem. There is probably other ways to refine the code, but what I provided you will spit out those 121 numbers in the exact order you provided.

Hope this helps!

• bionictiki

Member

1 Points

3 Posts