I certainly apologize for all my questions. Honestly I do read as much as I can and try to find answers for myself. Many questions I do find the answers for. I'm not seeing this one.
I'm just trying to find or create an equivalent to a Label or a way to GOTO something. I'll try to give an example.
I will shuffle a combination. But I don't want any of the numbers to be the same. We'll just say 6 numbers, all random from 0 to 5.
Create LIST
Add first Random Number (0-5) to LIST
Create FOR/NEXT from 1 to 5 for the next numbers
r = Random Number
Nest another FOR/NEXT to check previous numbers to see if r = any of those numbers
If it does, go back and generate another number.
So how can I make it go back and create another number?
If you want it to go back, that's what a while loop is good for:
numbers = NewList()
list add (numbers, GetRandomInt(0, 5))
for (i, 1, 5) {
isduplicate = true
while (isduplicate) {
r = GetRandomInt (0, 5)
isduplicate = false
foreach (existing_number, numbers) {
if (existing_number = r) {
isduplicate = true
}
}
}
list add (numbers, r)
}
However, in this case you don't need the inner loop, and you can make it a lot smoother:
numbers = NewList()
r = GetRandomInt (0, 5)
list add (numbers, r)
for (i, 1, 5) {
while (ListContains (numbers, r)) {
r = GetRandomInt (0,5)
}
list add (numbers, r)
}
Or, a more common way to perturb a list:
remaining_numbers = Split("0;1;2;3;4;5")
shuffled_numbers = NewList()
for (1, 0, 5) {
r = PickOneString (remaining_numbers)
list remove (remaining_numbers, r)
list add (shuffled_numbers, ToInt(r))
}
Sorry to say, there isn't a GOTO statement. That's pretty normal for any modern programming language.
But on the bright side, asking "How can I do this without GOTO" nearly always results in a more efficient algorithm.
A brief list of situations where you might want to use goto if you started programming on a language that has it, and the usual recommendations for how to deal with them:
while loop, setting a boolean variable to let Quest know it should repeatif statement to skip over the code in betweenreturnto get out of it immediately.I can't believe I didn't think of While. Slap me with the idiot stick. Thank you once again.
In my defense I have really only mingled with BASIC most of my life.