VB.NET

List Every Nth

Console.WriteLine

Module Module1
Sub Main()
*' Compute some modulo expressions with Mod.*
Console.WriteLine(5 Mod 3)
Console.WriteLine(1000 Mod 90)
Console.WriteLine(100 Mod 90)
Console.WriteLine(81 Mod 80)
Console.WriteLine(1 Mod 1)
End Sub
End Module2
10
10
1
0

For

If Then

Module Module1
Sub Main()
*' Loop through integers.*
For i As Integer = 0 To 200 - 1
*' Test i with Mod 10.*
If i Mod 10 = 0 Then
Console.WriteLine(i)
End If
Next
End Sub
End Module0
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190

Boolean

Module Module1
Function IsOdd(ByVal number As Integer) As Boolean
*' Handle negative numbers by returning the opposite of IsEven.*
Return IsEven(number) = False
End Function
Function IsEven(ByVal number As Integer) As Boolean
*' Handles all numbers because it tests for 0 remainder.*
*' ... This works for negative and positive numbers.*
Return number Mod 2 = 0
End Function
Sub Main()
For i = -10 To 10
Console.WriteLine(i.ToString() + *" EVEN = "* + IsEven(i).ToString())
Console.WriteLine(i.ToString() + *" ODD = "* + IsOdd(i).ToString())
Next
End Sub
End Module-10 EVEN = True
-10 ODD = False
-9 EVEN = False
-9 ODD = True
-8 EVEN = True
-8 ODD = False
-7 EVEN = False
-7 ODD = True
-6 EVEN = True
-6 ODD = False
-5 EVEN = False
-5 ODD = True
-4 EVEN = True
-4 ODD = False
-3 EVEN = False
-3 ODD = True
-2 EVEN = True
-2 ODD = False
-1 EVEN = False
-1 ODD = True
0 EVEN = True
0 ODD = False
1 EVEN = False
1 ODD = True
2 EVEN = True
2 ODD = False
3 EVEN = False
3 ODD = True
4 EVEN = True
4 ODD = False
5 EVEN = False
5 ODD = True
6 EVEN = True
6 ODD = False
7 EVEN = False
7 ODD = True
8 EVEN = True
8 ODD = False
9 EVEN = False
9 ODD = True
10 EVEN = True
10 ODD = False

Dictionary

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on Aug 8, 2023 (edit link).