YouTip LogoYouTip

Perl Unless Statement

# Perl UNLESS Statement [![Image 4: Perl Conditions](#) Perl Conditions](#) An `unless` statement consists of a boolean expression followed by one or more statements. ### Syntax The syntax is as follows: unless(boolean_expression){ # Executes when the boolean_expression is false} If the boolean_expression evaluates to `false`, the code block inside the `if` statement will be executed. If the boolean_expression evaluates to `true`, the first set of code after the `if` statement (after the closing brace) will be executed. ### Flowchart !(#) ## Example #!/usr/bin/perl$a = 20; # Use unless statement to check boolean expression unless($a<20){# Executes when the boolean expression is false printf"a is greater than or equal to 20n"; }print"The value of a is: $an"; $a = ""; # Use unless statement to check boolean expression unless($a){# Executes when the boolean expression is false printf"Condition a is falsen"; }print"The value of a is: $an"; Executing the above program produces the following output: a is greater than or equal to 20 The value of a is: 20Condition a is false The value of a is: [![Image 6: Perl Conditions](#) Perl Conditions](#)
← Perl Unless Elsif StatementPerl If Elsif Statement β†’