fn: for
[contents]

Contents

Syntax

The syntax for for loops is:

f++:  
for{options}(pre-loop code; condition; post-iteration code)
{
	//loop code-block
}

n++:  
@for{options}(pre-loop code; condition; post-iteration code)
{
	//loop code-block
}

Note: Single-line code blocks do not need to be enclosed in parentheses.

Description

The for function takes three parameters separated by ;, the first parameter is parsed before entering the loop, the second parameter specifies a loop condition and the third parameter is parsed at the end of each loop iteration. for calls loop through the code-block following the call while the loop condition does not evaluate to 0 (for for loops the loop condition is evaluated before each iteration of the loop code-block).

Note: f++ is used for for call parameters, even for n++. If you accidentally use n++ for the parameters it will most often run without any syntax or semantic errors anyway.

Note: If not writing to the output file Nift will skip to the first non-whitespace (ie. to the first character that is not a space, tab or newline) after a for loop and inject it to the output file where the call started. If you want to prevent Nift from doing this put a '!' after the loop, eg.:

@for{!o}(pre-loop code; condition; post-iteration code)
{
	# block
}!

Options

The following options are available for for loops:

option description
f++ parse for loop code-block with f++
n++ parse for loop code-block with n++
!o do not add output
s add scope
!s do not add scope
!\n do not add newline between each loop iteration
\n add double newline between each loop iteration
eob="value" add value between each loop iteration
option description

f++ example

Examples of for being used with f++:

for(int i=0; i < 10; i+=1)
	console("i: ", i)

for{!s, !o}(int i=0; i<10; i+=1)
	console("i: $[i]")

n++ example

Examples of for being used with n++:

@for(int i=0; i < 10; i+=1)
	@console("i: ", i)

@for{f++, !s, !o}(int i=0; i<10; i+=1)
	console("i: $[i]")

Sponsors