need help with my first "For Loop" assigment, any suggestion would really help!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ed5195
    New Member
    • Oct 2013
    • 3

    need help with my first "For Loop" assigment, any suggestion would really help!

    All programming languages have a loop capability. Looping is the program logic’s ability to repeat one or more lines of code either:
    1. A set number of times, a “for loop” (i.e. 10, 100, 500, 763 or more times)
    2. An “unknown” number of times (i.e. loop terminates if a tested condition becomes “true” or as long as the tested condition remains “false”), a “while” loop, a “do until” loop, a “do while” loop.

    This Lab exercise demonstrates the use of the “For Loop”, a standard loop in all programming languages. Visual Basic’s standard For Loop format looks like:

    For N = 1 To 100
    Loop line 1 code
    Loop line 2 code
    Loop line 3 code
    Loop line N code
    Next N

    The loop code needs:
    1. A “loop counter variable” (N in the above example) to keep track of how many iterations this loop has run
    2. A starting value (i.e. 1 in the above example)
    3. A stop value (i.e. 100 in the above example)

    The loop will start at 1 and increment by 1 until the counter exceeds 100. The loop will then stop at that point. We can substitute variables for the start and stop numeric constant values such as:
    For N = 1 To NumberofTimes
    Lines of Loop code
    Next N

    This Lab Assignment will allow the user to:
    1. Enter a positive number (we will dispense with GIGO code)
    2. Run a For Loop from 1 to N times keeping a running count of the loop iteration values (i.e. 1 + 2 + 3 + 4 + 5 + 6 +…+ N)
    3. Display that count in a Label
    4. You will need a textbox to hold the value that the user enters, a label to display the final total, a button to calculate, a button to clear the label and the textbox, and a button to quit the VB application

    The basic loop logic looks like:

    For N = 1 To NumberofTimes
    Total = Total + N
    Next N
    Attached Files
  • ed5195
    New Member
    • Oct 2013
    • 3

    #2
    Code:
    1.	Public Class Form1
    2.	
    3.	    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    4.	        End
    5.	    End Sub
    6.	
    7.	    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    8.	        Label1.Text = Nothing
    9.	        TextBox1.Text = Nothing
    10.	    End Sub
    11.	
    12.	    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    13.	        Dim total As Integer = Val(TextBox1.Text)
    14.	        Dim N As Integer = 0
    15.	        For N = 1 To 100
    16.	            Do Until False
    17.	                total = total + N
    18.	            Loop
    19.	        Next N
    20.	        Label1.Text = total & N 
    21.	    End Sub
    22.	End Class
    sorry first time user.
    Last edited by Rabbit; Oct 28 '13, 08:00 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.

    Comment

    Working...