kinx

Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.

This project is maintained by Kray-G

If-Else statement

Overview

if-else statement is a conditional jump. else clause is not always necessary.

if (a == 0) {
    // then clause
}

Here is the example with else clause.

if (a == 0) {
    // then clause
} else {
    // else clause
}

You can combine multiple if-else statements like C.

if (a == 0) {
    // then clause
} else if (b == 0) {
    // next if-else statement
} else {
    // else clause
}

Examples

Example 1. Normal case

Code

var age = 10;
if (age < 20) {
    System.println("young");
} else {
    System.println("adult");
}

Result

young

Example 2. No else clause

Code

var age = 10;
if (age < 20) {
    System.println("young");
}

Result

young

Example 3. If-else combination

Code

var age = 20;
if (age < 20) {
    System.println("young");
} else if (age > 20) {
    System.println("adult");
} else {
    System.println("just 20");
}

Result

just 20