Professional Documents
Culture Documents
The Ring Programming Language Version 1.5.4 Book - Part 75 of 185
The Ring Programming Language Version 1.5.4 Book - Part 75 of 185
if you don’t like the ‘other’ keyword in switch statement Then you can use the ‘else’ keyword.
Also you can replace ‘else’ with ‘other’ in if statement.
i.e. ‘other’ keyword is the same as ‘else’ keyword.
Example:
x = 1
switch x
on 10
see "10" + nl
else
see "not 10" + nl
end
Output:
not 10
switch x
on 1 see "one" + nl
on 2 see "two" + nl
end
Output:
if statement..
one
for loop..
12345678910
switch...
one
try catch...
catching error
switch x {
on 1 see "one" + nl
on 2 see "two" + nl
}
62.10. Using braces to start and end different control structures 716
Ring Documentation, Release 1.5.4
x = 1 / 0
catch
see "catching error" + nl
}
Output:
if statement..
one
for loop..
12345678910
switch...
one
try catch...
catching error
We can replace the ‘on’ keyword with ‘case’ keyword in the switch statement.
Example (1) :
for x=1 to 10
switch x
case 1 put "one" + nl
case 2 put "two" + nl
case 3 put "thre" + nl
else put "else" + nl
end
end
Example (2) :
for x=1 to 10 {
switch x {
case 1 put "one" + nl
case 2 put "two" + nl
case 3 put "thre" + nl
else put "else" + nl
}
}
We can use the ‘def’ keyword as the ‘func’ keyword to define functions and methods.
Example:
one() two()
Example:
load "stdlib.ring"
import mypackage
new myclass {
myfunc()
}
package mypackage
{
class myclass
{
func myfunc
{
print("Hello, World!\n")
}
}
}
Example:
import mypackage
new myclass {
myfunc()
}
package mypackage
class myclass
def myfunc
put "Hello, World!"
end
end
end
Example:
import mypackage
package mypackage
class myclass
func myfunc
see "welcome" + nl
endfunc
endclass
endpackage
SIXTYTHREE
Using this library we can add the type information to the source code which will be very useful for tools like
• Code Editors
• Static-Analysis
Note: Ring is a dynamic language, No type checking will be done by the compiler.
63.2 Example
see sum(3,4) + nl ;
see sayHello("Mahmoud");
The Type Hints library is very powerful and will support user types (Classes) automatically
Example:
load "typehints.ring"
import mypackage
720
Ring Documentation, Release 1.5.4
test() { main([:one,:two,:three]) }
package mypackage {
public class myclass {
public static void func main(list args) {
see "welcome" + nl
see args
}
}
}
Also you can use the types inside the code (not only the function prototype)
Example:
load "typehints.ring"
63.5 Rules
• To use the types in the function prototype you must use ‘(‘ and ‘)’ around parameters
• To use the types in the function code, You must set the variable value (Assignment).
The next types are defined by the library
# Low Level Types
char
unsigned
signed
int
short
long
float
double
void
# Other
public
static
abstract
protected
override
SIXTYFOUR
Step 1:
Copy c:\ring\bin folder to be for example c:\myapp
Step 2:
Rename c:\myapp\ring.exe to c:\myapp\myapp.exe
Step 3:
Create a file c:\myapp\ring.ring
And write
Load "myapp.ring"
When you run myapp.exe the file ring.ring will be executed automatically
So your file myapp.ring will be called and executed
Or just rename myapp.ring to ring.ring
It’s a fast way to distribute applications.
Step 1:
Execute the next command
ring myapp.ring -go
This will generate one object file (myapp.ringo) from the project files (*.ring)
Step 2:
Rename myapp.ringo to ring.ringo
When you run the executable file (ring.exe) or (myapp.exe) the file ring.ringo will be executed.
723
Ring Documentation, Release 1.5.4
There are many tools that you can use to distribute your application.
Check : nullsoft scriptable install system
URL : http://nsis.sourceforge.net/Main_Page
Ring can be embedded in a Qt projects or LibSDL projects to build Mobile applications and Games.
You can build the Qt project or the LibSDL project and get the Android package directly (*.apk)
Check Ring distributions for Mobile development using Qt or LibSDL.