Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 4 / 68

Branching (the If statement)

This lesson covers how to write an If statement in VB.NET, with the aim of being able to branch on a condition.

If ... Then / ElseIf / Else / End If branches on a condition. It helps to picture it as an everyday judgement written down: if such-and-such, do this; otherwise, do that.

The sample code uses If / ElseIf / Else to print one of three messages depending on score. Needing Then at the end of the line, and always closing with End If, is particular to VB.NET.

A common early stumble is forgetting Then or End If. Stacking too many conditions also hurts readability, so pulling a complicated test out into its own function keeps the main code tidy.

In professional work, If statements are used in practically every program — switching a display on login state, validating input.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)