Jump to content


Need loop help (beginner)


1 reply to this topic

#1 harrisdefth

    New Member

  • Members
  • Pip
  • 2 posts

Posted 22 October 2009 - 11:31 AM

Hi I need some help with a loop

I want a random number to be generated that is not equal to 3 different, and previously defined variables.

The loop I have is like this one below

Help with Code Tags
VB.NET Syntax (Toggle Plain Text)

1. random = randomNum.next(0, 10)
2. while random = first or second or third
3. random = randomNum.next(0, 10)
4. end while

random = randomNum.next(0, 10) while random = first or second or third random = randomNum.next(0, 10) end while

first, second, and third are previously defined short integers that have different values.

I thought this would work however my program gets stuck in an endless loop =(

How do I define more than one requirement for a while loop? Apparently or isn't working for me

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5344 posts
  • LocationSanta Clara, CA

Posted 22 October 2009 - 05:12 PM

You probably need to write:

While (Random = First) Or (Random = Second) Or (Random = Third)

The parentheses probably aren't strictly necessary, but they help readability. Anyway, the problem is that the things on each side of an "Or" or "And" have to be fully formed conditions. Even though in English you can say something like "equals first, or second, or third", programming languages don't work that way.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users