Results 1 to 2 of 2

Thread: combining loops

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Posts
    98

    combining loops

    any help on how i would combine these two loops into one do while loop?
    thanks!
    VB Code:
    1. If (num > 1) Then
    2.             Do While (num > 1)
    3.                 Do While (num Mod num1) = 0
    4.                     num2 = num \ num1
    5.                     If (num2 > 1) Then
    6.                         txt2 &= num1 & " * "
    7.                         num = num2
    8.                     Else
    9.                         txt2 &= num1
    10.                         num = 0
    11.                         Exit Do
    12.                     End If
    13.                 Loop
    14.                 If (num = 0) Then Exit Do
    15.                 num1 += 1
    16.             Loop
    17.             lblOutput.Text = "Prime factors of " & number & " are: " _
    18.             & txt1 & txt2
    19.         End If
    20.     End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: combining loops

    A Do loop just checks a boolean expression. The expression can be as simple as a single Boolean literal or as complex as you like:
    VB Code:
    1. Do While num > 0 AndAlso num Mod num1 = 0
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width