Difference between revisions of "User:Ulti/sandbox"

From Kolmafia
Jump to navigation Jump to search
imported>Ulti
imported>Ulti
(added a "for loops" section.)
Line 28: Line 28:
 
}
 
}
 
print(helloWorld());//prints "Hello world!" to kolmafia's command line interface.
 
print(helloWorld());//prints "Hello world!" to kolmafia's command line interface.
 +
</pre>
 +
==Simple For Loops==
 +
In PHP, you write simple for loops like so:
 +
<pre>
 +
for($i=1;$i<=5;$i++)
 +
{
 +
echo "Loop $i";
 +
}
 +
</pre>
 +
In Ash you write such loops like so:
 +
<pre>
 +
for i from 1 to 5
 +
{
 +
print('Loop '+i);
 +
}
 
</pre>
 
</pre>

Revision as of 14:45, 19 October 2014

  Ulti     Talk     My Contributions     My Sandbox     Nav Bar  
 This page is a sandbox used for testing my code before putting it live elsewhere on the wiki

migrating to ASH from PHP (work in progress)

ASH is basically half-ass Java because of feature limitations made specific for interacting with KoL.

Default Function Parameters

In PHP you can define default values for your arguments like so:

function helloWorld($msg='Hello world!')
{
	return $msg;
}
echo helloWorld();//prints "Hello world!" to the browser

In ASH, default parameters is accomplished like so:

string helloWorld(string msg)
{
	return msg;
}
string hellowWorld()
{
	string msg='Hello world!';
	return helloWorld(msg);
}
print(helloWorld());//prints "Hello world!" to kolmafia's command line interface.

Simple For Loops

In PHP, you write simple for loops like so:

for($i=1;$i<=5;$i++)
{
	echo "Loop $i";
}

In Ash you write such loops like so:

for i from 1 to 5
{
	print('Loop '+i);
}