Learn R Programming

RNetLogo (version 0.9.4)

NLDoCommandWhile: Repeats a command in the referenced NetLogo instance while a reporter returns TRUE.

Description

NLDoCommandWhile function executes a NetLogo command (submitted as a string) in the submitted NetLogo instance more than one time. It works like NLCommand but will be repeated as long as the reporter returns TRUE.

Usage

NLDoCommandWhile(condition, ..., max.minutes=10, nl.obj=NULL)

Arguments

condition
A string with a NetLogo conditional reporter.
...
An undefined number of string(s) with the NetLogo command(s) to be executed. See NLCommand for details.
max.minutes
(optional) If max.minutes > 0 the execution stops after the defined number of minutes (with an error). By default, all executions are stoped after 10 minutes, to prevent the execution of endless loops. If you need more time, increase the valu
nl.obj
(optional) A reference to a NetLogo instance created with NLStart.

Value

  • No return value.

Details

This function is used to execute a command for more than one time. It could be used, for example, to run a simulation (by calling "go") while a variable is below some limit. The condition is evaluted before the submitted commands are executed. If the condition is FALSE at the first evalutation, the commands will never be executed. Attention: Make sure that the condition switches from TRUE to FALSE sometime, otherwise you will run an endless loop (which is stopped after 10 minutes by default, see argument max.minutes).

See Also

NLCommand, NLDoCommandWhile, NLReport

Examples

Run this code
nl.path <- "C:/Program Files/NetLogo 5.0.3"
NLStart(nl.path)
model.path <- "/models/Sample Models/Earth Science/Fire.nlogo"
NLLoadModel(paste(nl.path,model.path,sep=""))
NLCommand("setup")
NLDoCommandWhile("burned-trees < 2200", "go")

Run the code above in your browser using DataLab