On the previous post i’ve talked about how to start your Hello, World! app in Ring.
It’s time to move on and got through The Variables.
Well, comparing to Python they both work in the same way, you just need to do this,
This is the syntax :
variable = value
x = 5 y = 10 see x + y + nl
Another one :
first = "Mercedes" last = "Benz" see first + "-" + last
Ring is a weakly typed language, to make it clear .. string + int = string & int + string = int.
see "Enter text : " give text see "Enter a number : " give number see 'before conversion : ' + type(number) + nl #type() just like in Python, is a function to know the type of a variable number = Number(number) #Number() is a function to convert string to number see 'after conversion : ' + type(number) + nl see 'final text : ' + text + " " + number
input : Jump Street input : 23 output : before conversion : STRING output : after conversion : NUMBER output : Jump Street 23
The example above, the number variable was int but it was converted to str.
Last one :
x = 2000 #x is a number y = "16" #y is a string see x + y #string (y) is converted to an int.
I think you now should be able to understand how it works.
I will add one last thing to the post and it’s ‘Comments’
It’s cool actually because you can use one of 3 types of commenting.
/* bla bla bla bla bla */ (Like C#)
# ding dong (Like Python)
// boom bam (Like PHP)
Simple as that.