Netscript Loops and Conditionals

Netscript loops are the same as JavaScript loops. For reference, you can see the JavaScript documentation for these here:

While loops

For loops

Conditionals (If/Else statements) An  block will consume an additional 0.20GB of RAM to run.

Code Examples
Here are some simple code examples that show the use of loops and conditionals in Netscript.

The following is a while loop that runs the hack Netscript function ten times.

The following is a while loop that runs the hack Netscript function continuously until the script is stopped.

The following is a for loop that runs the hack Netscript function ten times.

The following is a conditional that uses the getServerMoneyAvailable Netscript function to check how much money exists on the 'foodnstuff' server. If there is more than $200,000 on the server, then the server will be hacked. Otherwise, the money available on the server will be grown using the grow Netscript function.