Is code within a program always location specific? | SoloLearn: Learn to code for FREE!


Is code within a program always location specific?

I've been learning ruby, and it seems like things are very location specific within the text document itself. Example: x = 10 puts x # any code written in between these two lines treats x as 10 x += 10 puts x # any code written after this last line treats x as 20 So I'm imaging myself in the future becoming confused by the fact that WHERE within the document I add code is going to be so important going forward. How does this work, do I get used to thinking of code like this?

6/2/2017 11:05:02 PM

AJ Sellarole

6 Answers

New Answer


as long as you defined it first before you call an action there will be no problem


it could be better for you if you use comments :)


what do you mean b33


All comments are not seen if you run a program. Example: In HTML <!--this is comment--> every language has its comment bro so that you can note yourself.


Oh I see what you are saying. Use comments to keep things clear. So you are saying this location thing is the way it is? I'm forseeing many potential issues, what if I have multiple variables and want to use a version of a variable that has since been redefined? Can I refer to previous versiins of a variable within the document? Is a variable ever a true variable? Or it just means what it means for a certain number of lines and is otherwise different?


Of course it will be different if you use different set of codes. Ruby probably has code that can redefine a specific variable just like in all languages.