Last active
August 29, 2015 14:01
-
-
Save lucidguppy/d01fb6d4f2522edbadad to your computer and use it in GitHub Desktop.
Output hello 10 times with counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#string interpolation is similar to python - be sure to import string utils | |
import strutils | |
var output = "a $1 parrot" % ["dead"] | |
echo(output) | |
for time in countUp(1,10): | |
echo("I like traffic lights $time" % ["time", intToStr(time)]) | |
echo("But only when they're green") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import strutils | |
if contains("exterminate","term"): | |
echo("DESTROY!!!") | |
if "x" in "exterminate": | |
echo("EXTERMINATE!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#iterate over string | |
var greeting = "Always look on the bright side of life." | |
for c in greeting: | |
echo(c) | |
#indexing and slicing | |
echo("-------------------------") | |
echo(greeting[4]) | |
echo(greeting[4..10]) | |
echo(greeting[..14]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#print out ten lines | |
for x in countup(1,10): | |
echo("hello: ", x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment