Inverted syntax

Revision as of 21:56, 30 May 2011 by rosettacode>Markhobley (initial content)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In traditional syntax conditional expressions are usually shown before the action within a statement or code block:

Task
Inverted syntax
You are encouraged to solve this task according to the task description, using any language you may know.

<lang psuedocode> IF raining=true THEN needumbrella=true </lang>

In inverted syntax, the action is listed before the expression in the statement or code block:

<lang psuedocode> needumbrella=true IF raining=true </lang>

The task is to demonstrate support for inverted syntax forms within the language by showing both the traditional and inverted forms.

Perl

<lang perl>if ($guess == 6) { print "Wow! Lucky Guess!"; }; # Traditional syntax print 'Wow! Lucky Guess!' if ($guess == 6); # Inverted syntax (note missing braces) unless ($guess = 6) { print "Sorry, your guess was wrong!"; } # Traditional syntax print 'Huh! You Guessed Wrong!' unless ($guess == 6); # Inverted syntax

</lang>