Inverted syntax: Difference between revisions
Tcl doesn't do this |
→{{header|Perl}}: Add Python |
||
Line 16:
unless ($guess = 6) { print "Sorry, your guess was wrong!"; } # Traditional syntax
print 'Huh! You Guessed Wrong!' unless ($guess == 6); # Inverted syntax</lang>
=={{header|Python}}==
<lang python>x = truevalue if condition else falsevalue</lang>
{{omit from|Tcl|The language syntax really doesn't allow this.}}
|
Revision as of 14:35, 31 May 2011
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
In traditional syntax conditional expressions are usually shown before the action within a statement or code block:
<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>
Python
<lang python>x = truevalue if condition else falsevalue</lang>