Q:

Repeat the task using while loop until user clicks on “No” button?

Public Class Form2
    Dim ss As Boolean

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim i, z As Integer
        ss = False
        Butn_no.Focus()

        While ss = False
            Application.DoEvents()
            i = Val(InputBox("enter 1st number", "program#3"
                             ))
            z = Val(InputBox("enter 2nd number", "program#3"))
            If z = 0 Or i = 0 Then
                MsgBox("one of the given number is empty try again or not integer", vbCritical, "error")
            Else
                If z = i * i Then
                    MsgBox("second number is the sqaure of first number", vbInformation, "program#3")
                Else
                    MsgBox("second number is not the square of first" & vbNewLine & " first number = " & i.ToString & " 2nd number = " & z.ToString, MsgBoxStyle.OkCancel, "program#3")
                End If
            End If
        End While

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Butn_no.Click
        ss = True
    End Sub
End Class

This is working but next time when while executed I am unable to click on button 2 due to input box which is showing at the top, with this same method I stopped the loop which is appending text in textbox in my earlier program. I just want to stop loop execution on button pressed if anyone?

A:

Val returns a double and you have declared i as an integer. Same problem with z. Val is an old VB6 method. .Net has new methods to replace it. I used Integer.TryParse. If an non integer is entered it will not update the output variable which will remain 0. If the input is a valid Integer, i and z will be assigned the new value.
The Continue While takes the execution back to the top of the While.
Put your exit question in the loop. You can use Return to exit the Sub.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim i, z As Integer
    While True
        Integer.TryParse(InputBox("enter 1st number", "program#3"), i)
        Integer.TryParse(InputBox("enter 2nd number", "program#3"), z)
        If z = 0 Or i = 0 Then
            MsgBox("one of the given number is empty try again or not integer", vbCritical, "error")
            Continue While
        Else
            If z = i * i Then
                MsgBox("second number is the sqaure of first number", vbInformation, "program#3")
            Else
                MsgBox("second number is not the square of first" & vbNewLine & " first number = " & i.ToString & " 2nd number = " & z.ToString, MsgBoxStyle.OkCancel, "program#3")
            End If
        End If
        Dim Answer = DialogResult.Yes
        If Answer = MessageBox.Show("Do you want to quit?", "Quit?", MessageBoxButtons.YesNo) Then
            Return
        End If
    End While
End Sub

