btabeta.blogg.se

Info basic programming language tutorial
Info basic programming language tutorial




info basic programming language tutorial

Variables are initialized to zero by default unless specified otherwise. Y, z: int // declares y and z to have type `int` X = 1 // `1` is an untyped integer literal which can implicitly convert to `int`Ī variable declaration declares a new variable for the current scope. x: int = 1.0 // A float literal but it can be represented by an integer without precision lossĬonstant literals are “untyped” which means that they can implicitly convert to a type. In Odin, if a number constant can be represented by a type without precision loss, it will automatically convert to that type. A leading zero does not produce an octal constant (unlike C). If a number literal is suffixed with i, it is an imaginary number literal: 2i (2 multiply the square root of -1).īinary literals are prefixed with 0b, octal literals with 0o, and hexadecimal literals with 0x.

info basic programming language tutorial

A number that contains a dot is a floating point literal: 1.0e9 (one billion). A useful feature in Odin is that underscores are allowed for better readability: 1_000_000_000 (one billion). Numerical literals are written similar to most other programming languages.

  • \UNNNNNNNN - hexadecimal 32-bit Unicode character UTF-8 encoded (8 digits).
  • info basic programming language tutorial

  • \uNNNN - hexadecimal 16-bit Unicode character UTF-8 encoded (4 digits).
  • \xNN - hexadecimal 8 bit character (2 digits).
  • If the string passed to len is a compile-time constant, the value from len will be a compile-time constant. The length of a string can be found using the built-in len proc: len("Foo") Raw string literals are enclosed in single back ticks. Special characters are escaped with a backslash \. String literals are enclosed in double quotes and character literals in single quotes. This is to allow for future work on automatic documentation tools. Multi-line comments can be also be nested (unlike in C): /*Ĭomments are parsed as tokens within the compiler. Multi-line comments begin with /* and end with */.

    info basic programming language tutorial

    My_integer_variable: int // A comment for documentation Single line comments begin with //: // A comment Lexical elements and literals # Comments #Ĭomments can be anywhere outside of a string or character literal.






    Info basic programming language tutorial