Thursday, 12 October 2017

With... End With and Nested loops


With... End With

Module loops
   Public Class Book
      Public Property Name As String
      Public Property Author As String
      Public Property Subject As String
   End Class
   Sub Main()
      Dim aBook As New Book
      With aBook
          .Name = "VB.Net Programming"
          .Author = "Zara Ali"
          .Subject = "Information Technology"
      End With
      With aBook
          Console.WriteLine(.Name)
          Console.WriteLine(.Author)
          Console.WriteLine(.Subject)
      End With
      Console.ReadLine()
   End Sub
End Module

When the above code is compiled and executed, it produces the following result:
VB.Net Programming
Zara Ali
Information Technology

Nested loops

Module loops
   Sub Main()
      ' local variable definition
      Dim i, j As Integer
      For i = 2 To 100
          For j = 2 To i
              ' if factor found, not prime
              If ((i Mod j) = 0) Then
                  Exit For
              End If
          Next j
          If (j > (i \ j)) Then
              Console.WriteLine("{0} is prime", i)
          End If
      Next i
      Console.ReadLine()
   End Sub
End Module

https://www.youtube.com/channel/UCKLRUr6U5OFeu7FLOpQ-FSw/videos

0 comments

Post a Comment