mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-13 10:14:58 +02:00
Removed common operations, explained continue
This commit is contained in:
@@ -41,17 +41,6 @@ This can work as a multiline comment.
|
|||||||
Or for unparsable, broken code
|
Or for unparsable, broken code
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#
|
|
||||||
# Common Operations on Basic Types
|
|
||||||
#
|
|
||||||
|
|
||||||
# Strings
|
|
||||||
let
|
|
||||||
phrase = "Nim is a"
|
|
||||||
nim = phrase[0..5]
|
|
||||||
fullPhrase = phrase & "programming language."
|
|
||||||
length = len(fullPhrase) # Or: fullPhrase.len
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Data Structures
|
# Data Structures
|
||||||
#
|
#
|
||||||
@@ -218,8 +207,8 @@ for line in splitLines(myString):
|
|||||||
echo(line)
|
echo(line)
|
||||||
|
|
||||||
for i, c in myString: # Index and letter. Or `for j in` for just letter
|
for i, c in myString: # Index and letter. Or `for j in` for just letter
|
||||||
if i mod 2 == 0: continue # Compact `if` form
|
if i mod 2 == 0: continue # Skip rest of iteration
|
||||||
elif c == 'X': break
|
elif c == 'X': break # Compact `if` form
|
||||||
else: echo(c)
|
else: echo(c)
|
||||||
#
|
#
|
||||||
# Procedures
|
# Procedures
|
||||||
@@ -259,7 +248,7 @@ proc pluralize(a: int): string =
|
|||||||
#
|
#
|
||||||
|
|
||||||
# Because Nim compiles to C, FFI is easy:
|
# Because Nim compiles to C, FFI is easy:
|
||||||
|
#
|
||||||
proc strcmp(a, b: cstring): cint {.importc: "strcmp", nodecl.}
|
proc strcmp(a, b: cstring): cint {.importc: "strcmp", nodecl.}
|
||||||
|
|
||||||
var cmp = strcmp("C?", "Easy!")
|
var cmp = strcmp("C?", "Easy!")
|
||||||
|
Reference in New Issue
Block a user