Chapter 1. Kenya Syntax

Tristan Allwood

Table of Contents

Comments
Methods
Method Declarations
Returning from a Method
Method Invoking
Methods Example
Control Flow
For Loops
While Loops
If Statements
Switch Statements
Assertions
Variables
Operators
Notes:

Comments

Comments in any programming language are important, as they allow the programmer to annotate the program code, to make it clearer and more easily maintainable.

There are two types of comments in Kenya, Block Comments and Line Comments (these are the same as in Java).

Block comments can be used to mark several lines, or just a few characters as "comments" ( i.e. not Kenya program code ).

Block comments start on a /* symbol, and then finish on the first */ ( this property means they cannot be nested ).

Line comments are denoted by //, and make everything to the right of them on a line "commented out".

Example 1.1. Comments Example

	/* This is a block comment
	 * that spreads across multiple lines.
	 * The *'s on the left are a style that helps to see
	 * what is a comment and what is not in source code.
	 */
	
	void main(){
		int a = 3;

// 		This line is a comment		
		int a = a + 2; // A now equals 5
		
		/* these lines are commented out - i.e. they are not seen
		 *  when Kenya compiles / executes / translates them.
		 * a = a + 1;
		 * a = a / 2;
		 * a = ??? <- What should I put here?
		*/

		myFunction(a);
	}
	
	/* on the line below I have commented out the second argument to the function
	 * so it is really a 1 argument function; note, just because you can do this,
	 * DOESNT mean you should do this :) */
	 
	void myFunction( int a /*, int b */ ) {
//		println(a + b); This line is commented out thanks to line comments.
		println(a);
	}