For Loops to prompt a user for 5 facts about a topic.

Matthew Turcotte 1 Reputation point

Any suggestions on how to start a for loop to prompt the user for five facts about a topic. I am a beginner and have not done well with for loops wit past sections and am trying to grasps the concept. I am supposed to create the facts had the user use a input box to get a fact set to a string variable add the fact to the list box. I have a menu box that I have added add fact, remove fact, clear list, and close. I am pretty lost on how to start this code if anyone has any educational tips that they could share with me I would appreciate it.

An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
1,830 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 29,236 Reputation points Microsoft MVP

    Here is the base logic where entering nothing or pressing cancel will exit the loop.

    Public Class Form1
        Private Sub EnterFactsButton_Click(sender As Object, e As EventArgs) Handles EnterFactsButton.Click
            Dim factIndex = 1
            While True
                Dim value = InputBox($"Enter fact {factIndex}")
                If String.IsNullOrWhiteSpace(value) OrElse factIndex = 5 Then
                    Exit While
                    factIndex += 1
                End If
            End While
        End Sub
    End Class
    No comments