# HC's simple programming language

From version 1.0, HC includes a simple programming language with a syntax similar to C, which can be used for teaching basics of programming or writing simple calculations.## Supported logic operations

As of version 1.0, HC supports the following logic operators:& / && | and, returns 1 if both of its arguments are not false |

| / || | or, returns 1 if one of its arguments is not false |

! | logical NOT, returns 1 if its argument is false, 0 otherwise |

== | equals, returns 1 if its arguments are equal |

!= | not equals, returns 1 if its arguments are not equal |

> | larger than |

< | smaller than |

>= | larger or equal than |

<= | smaller or equal than |

## Supported structures

**From HC version 3.0**, control structures behave simply like any other function. The available structures are if(), for() and while(). To get more information, simply run help("if"), help("for") or help("while") in the HC prompt, or see below for examples of usage.

## Examples

### P1

Solving Project Euler's first problem with HC:s = 0(result of this program and the solution of the problem as it was on 5.3.2010 should befor(j=0, j<1000, j+=1,if(j%3 == 0 | j%5 == 0, s+=j)) print(s)

**233168**)

### P2

Solving Project Euler's second problem with HC:s = 0 x = 0 j = 1(result of this program and the solution of the problem as it was on 5.3.2010 should bewhile(x <= 4000000, x = fibo(j);if(x%2 == 0, s+=x); j+=1; ) print(s)

**4613732**)

### Estimating pi toy monte carlo program

dstfromcenter(x,y) = sqrt(abs(0.5-x)^2 + abs(0.5-y)^2) s = 0 tot = 5000 for(j=0, j<tot, j+=1, if(dstfromcenter(rand(), rand()) < 0.5, s+=1) ) print("I estimate that pi is : ", 4*s/tot)

Back to documentation index