Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program should use two for loops to display a table consisting of four rows

ID: 3579126 • Letter: T

Question

This program should use two for loops to display a table consisting of four rows and two columns. The first column should contain the numbers 10, 12, 14 and 16. The second and subsequent columns should contain the result of multiplying the number in the first column by the numbers 2 through 5. For example the first two rows of the table should look like this:

10 20 30 40 50
12 24 36 48 60

Public Class MainForm
Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.Click
Dim Product As Integer
For i As Integer = 10 To 16

tableLabel.Text = tableLabel.Text & ControlChars.NewLine & i.ToString
For j As Integer = 2 To 5
Product = i * j
tableLabel.Text = tableLabel.Text & "" & Product

Next j
Next i

End Sub

Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub
End Class

Explanation / Answer

For ... Next by default takes a step of 1. But it can be managed by exclusively specifying the step keyword.

So, if you want to make the step 2 instead of 1, we have to specify that in the loop. So, this is how you can achieve your requirement, assuming everything else working fine:

Public Class MainForm
Private Sub displayButton_Click(sender As Object, e As EventArgs) Handles displayButton.Click
Dim Product As Integer
For i As Integer = 10 To 16 Step 2

tableLabel.Text = tableLabel.Text & ControlChars.NewLine & i.ToString
For j As Integer = 2 To 5
Product = i * j
tableLabel.Text = tableLabel.Text & "" & Product

Next j
Next i

End Sub

Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub
End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote