Nested If and Single line if statement
By: Issac
Nested If statement
Option Strict On
Imports System
Module Module1
Sub Main( )
Dim temp As Integer = 8
If temp <= 8 Then
If temp = 8 Then
Console.WriteLine("temp = 8")
Else
Console.WriteLine("Temp: {0}", temp)
End If
End If
End Sub
End Module
Nested if statement helps to check multiple number of conditions here in this example we take a variable temp and assign the value of 8 to it now in the first if statement we check whether temp is less than or equal to 8(which is true) so it will get into the next if statement which checks whether temp is equal to 8(which is again true) and prints temp =8.
Single line if statement
public class Test
public Shared Sub Main
Dim Score As Integer
Score = 23
'Single line If statement.
If Score < 50 Then Console.WriteLine("Failed.") : Console.WriteLine("Please try again.")
'Multi-line If statement.
If Score < 50 Then
Console.WriteLine("Failed.")
Console.WriteLine("Please try again.")
End If
End Sub
End class
In this example we have shown both multi-line and single line if statements, single line if statements though may look complex if you have large number of conditions is effective and helpful to reduce the number of program lines.
Archived Comments
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Using Resume Next and Resume Line in VB.net
Using On Error GoTo 0 in VB.net
Getting an Exception's Number and Description in VB.net
Raising an Exception Intentionally in VB.net
Exception Filtering in the Catch Block in VB.net
Using Multiple Catch Statements in VB.net
Throwing an Exception in VB.net
Throwing a Custom Exception in VB.net
Changes in Controls from VB6 to VB.net
Unstructured Exception Handling in VB.net