jeudi 19 août 2021

If statement isn't working inside a Do While loop

I'm doing this exercise: Write a VB program in Windows forms application that prints all even integers which are divisible by 4 between 1 and 99 using Do While loop structure.

this is my code but the output will be the list of numbers from 1 to 100.
Why is the if statement not working?

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim i As Integer = 0

    If (i Mod 4 = 0) Then
        Do While (i < 100)
            i = i + 1
            ListBox1.Items.Add(i)
        Loop

    End If
End Sub

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs)


End Sub
End Class

Aucun commentaire:

Enregistrer un commentaire