Skip to content

rajlang/Syntax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Raj Lang Syntax

Syntax of raj programming language

🤝 Contributing

Please Vote for proposals or propose new at Dicussions

Syntax

// Single line comment
# This is also single line comment

/*
* Multi
* line
* comment
*/

// Defining a function

fn main() {
  print("Hello World"); // Without new line
  println("Hello World"); // With new line
  
  // Prints "Hello, World! - Hello, World! - ... 8 times"
  for(i = 0; i < 10; i++) {
    print("Hello, World!", end=" - ");  // custom end character
  }
}

// Defining variables

let myVar1 = 1; // mutable variable with local scope
// or
myVar2 = 10 // doesn't need keyword to declare. if already declared then changes it
const PI = 3.1415; // im-mutable constant with global scope

// Loops

// for
for ( i = 0; i < 10; i++ ) {
  println(i);
}

// while (not infinite loop)
while (sayHello) {
  print("Hello World");
  break;
}

// loops infinitely with optimizations
loop {
  println("I love Programming");
}

// do-while
do {
  println("Do");
}
while (true) {
  println("while");
  break;
}

// arrays

myArr = [ 1, 2, 3, 4, 5 ];

myNestedArr = [ 1, [ 2, 20, 200, 2000 ], 3, 4, [ 5, 4, 3, 2, 1 ] ]; // arrays within array


// Object

myObj = {
  name: "Rajaniraiyn",
  age: 17,
  nationality: "Indian"
  location: {
    village: "Okkur",
    district: "Sivagangai",
    state: "Tamilnadu",
    country: "India",
  },
}

// Conditionals

if ( a == b) {
  println("Hello World");
} else {
  println("Hello Everyone");
}

// template literals

`
this is the 
m
u
l
t
i
line
template-literal
`
"""
this is also a 
m
u
l
t
i
line
template-literal
"""

// switch statements


switch(a) {
  1 || 3 :
    println("a is one");
    break;
    
  2 || 4:
    println("a is two");
    break;
    
  default:
    println("a is not one or two");
    break;
}