Nested Loop For Lotto
BlitzMax Forums/BlitzMax Tutorials/Nested Loop For Lotto
| ||
Hi I am new to the group, and new to VB. I ran programs I wrote on my Commodore years ago but things have changed. I am running this on my iMac Snow Leopard. Running this routine gets a 'Next without matching For' error message. Moving lines around or changing them gets an 'End of Life' error message. I have scoured the 'net for 2 days and find no way to fix this. Is it obsolete code? For a = 1 To 10 For b = 5 To 15 For c = 9 To 20 If a >= b Then If b >= c Then EndIf Print a, b, c Next |
| ||
The code doesn't make sense and wouldn't make sense in VB. You have two 'ifs' but only one 'endif' and you have 3 'fors' but only one next (3 fors need 3 nexts), hence the error. If you indent your code, these kinds of error will be more easy to spot, e.g. For a = 1 To 10 For b = 5 To 15 if a >= b Then 'a is greater than or equal to b endif next Print a, b Next |
| ||
Thanks, I knew it had to be something simple. -Taggart |
| ||
Now I get 'Compile Error' 'Too many function parameters' The line Print a, b is lit |
| ||
Not as simple as it used to be but making progress. Thanks all |
| ||
Actually try this -For a = 1 To 10 For b = 5 To 15 if a >= b Then 'a is greater than or equal to b endif next Print a + " " + b Next The Print statement doesn't work like it used to in BASIC. Print in BlitzMAX simply writes a string to the standard IO stream which ends with a newline character. To print two values you now need to combine them as a single string. The '+' concatenates pieces of the string and the " " is simply a space in between. |
| ||
Thanks I will try that :) |
| ||
That print command works great ... thanks! |
| ||
I have managed to make a program that works well. It might not be as elegant as some would have it but with my limited knowledge I think it's fine, and produces what it is intended to produce, 6 lottery numbers with no duplicates. In this example only 'For a' and 'For b' overlap (number 8 in both lines) but I have run it with all lines overlapping and it prints no duplications. I don't know why the 'For g' must be in place, but without it the last number prints the same repeated '48' all the way down the list. And I read here and there that no one likes the GoTo statement, but I can find no simple substitute. For a = 4 To 8 For b = 8 To 12 For c = 16 To 20 For d = 28 To 32 For e = 37 To 41 For f = 43 To 47 For g = -1 To -1 If a >= b Goto Here If b >= c Goto Here If c >= d Goto Here If d >= e Goto Here If e >= f Goto Here Next Print a + " " + b + " " + c + " " + d + " " + e + " " + f #Here Next Next Next Next Next Next |
| ||
Wow?!?!?! oOoO... What does it do, exactly? |
| ||
I suspect you're trying to do something like this ...' ** Lotto numbers generation example ** SuperStrict Global temp:Int, compare:Int, flag:Int, a:int Global Numbers:Int [6] SeedRnd MilliSecs() ' Generate a random seed or you get the same six numbers constantly For temp = 1 To 6 RandomNumber Numbers[temp] = a Print Numbers[temp] Next Function RandomNumber() flag = true Repeat a=Rnd (1,49) For compare=1 To temp If Numbers[compare]=a flag = False EndIf Next Until flag = true End Function Kind of hacked together but it seems to work and does check to make sure that you don't get duplicate numbers. I suspect someone else will throw in something a little more readable and much more efficient anyway :) |
| ||
TaskMaster: It wheels any numbers from 1 to 54 (for example) in 6 positions in whatever position you put them in without duplicating any of them. You can wheel all or part of a complete lotto game. It can also be scaled back to a Pick 5 game or whatever. Xerra: I could not get your game to run. Had a problem with, If Numbers[compare]=a But I see the logic in it. Thanks all! |
| ||
This is either the weirdest tutorial I've ever seen, or it's in the wrong forum? |
| ||
Sorry, being new around here I started this in the wrong forum. But if you want a lottery wheel that lets you pick what numbers to use and uses no random numbers (you can buy those at the store) this is a good place to start. |