Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

If statement: Difference between revisions

From Coderwiki
info, pseudocode example, c example
 
(No difference)

Latest revision as of 21:35, 12 August 2025

An if statement is a type of selection where the program runs a block of code 'if' a condition is true.

This can be very useful for branching your code - making decisions and running different code based on different input.

This is often more useful than a switch statement or match statement for non-exhaustive conditions or pattern matching.

Pseudocode example

edit edit source

This program will print 5 is less than 7 if the condition is true:

IF 5 < 7 THEN
    PRINT "5 is less than 7"
ENDIF

This C example does the same as the pseudocode example:

if (5 < 7) {
    printf("5 is less than 7");
}