I recommend you C# because of visual studio 2012 express.
It is ok because it looks like c++, you write less words compared to visual basic, it's quite close to Java, and it's what tekla expects to find when it will compile it.
The thing is after you learn one language, you'll be able to learn other languages more easily.
So download and install visual studio express. You'll find Visual Studio Express for Desktop in your start menu, run it. Register it's free.
Click New Project, Select on the left Visual C# and select console application.
You will be seeing something like this:
The default colors are light theme I prefer dark so you can change the colors of all text and windows from Tools->Options-> Environment->General, Color Theme: Dark.
At the bottom of the window you will see Output or Error List, while writing stuff it's better to switch to Error List. Visual Studio will notify you of syntax errors while writing.
There's a button at top called Start, you will press that in order to start your program.
The text which starts with two slash // is called comment Visual Studio will ignore it.
Programmers use comments to remember what they wrote it happens that code becomes long so they will forgot. The same when there's more than one guy involved.
In this case my comment "//here is where you write code" it is to show you where you can write your first lines of code.
The text bla bla bla is not according to syntax and so 4 errors, Visual Studio doesn't know what bla is.
Here is a sample, to make it work just write it and run it:
First line:
1) int c;
2) c = 2;
3) int a = 5;
4) int b = a + 5;
5) Console.WriteLine©;
6) Console.WriteLine(b);
7) Console.ReadLine();
1) I defined a variable called "c" which has the integer type (remember from math classes)
2) I assigned value "2" to variable "c".
3) I defined a variable called "a", integer type and assigned value "5" to it.
4) I defined a variable called "b", integer type and assigned a value equal to a value +"5" to it.
5) I used the object called Console provided by the framework, from it I called the function WriteLine with variable c value as parameter.
Function are like in math f(x)=x+3 which means if I call in programming f(4) I will receive a value of 4+3=7.
WriteLine function has the purpose to write a value as text on the screen.
6) The same stuff but with b value;
7) I used the object called Console provided by the framework, from it I called the function ReadLine without any parameter. ReadLine waits for user to press enter. It's purpose is to pause the program until user input.
The basic variable types and more samples are here:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:
http://forum.civilea.com/thread-27464.html
***************************************
Here a different sample:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:
http://forum.civilea.com/thread-27464.html
***************************************
double result=0;
I defined a variable of type double (this is for floating point numbers).
for (int i = 0; i < 1000; i++)
translates into for i=0, while i is smaller than 1000, increment i by 1.
This means the program will repeat what's between the braces {result=result+i} for each value of i, until it reaches 1000. Then it will go to the next statement which is Console.WriteLine(result).
The for.. thing is called a loop.
There are 3 basic loops for, while, until
for is used when you know how many times you wish to repeat a statement.
while and until are used when you expect to achieve a value but don't know how many times you have to repeat a statement. while and until can lead to infinite loops (what you're seeing when software has bugs and keeps using processor at maximum but without any results or response)
So instead of the loop the above code would look like this:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:
http://forum.civilea.com/thread-27464.html
***************************************
becomes:
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:
http://forum.civilea.com/thread-27464.html
***************************************
In other words result=0+1+2+3+...+998+999
From math this is 999*(999+1)/2=499500
What computer does is to increment each step the variable i with 1. Check if it's new value is smaller than limit i<1000 and if it is add it to variable result.
Because the variable result is defined before the loop it's value will be kept each time.
So the code will in fact look like this
i=0;
if(i<1000)
{
result=result+i;
}
i=i+1;
if(i<1000)
{
result=result+i;
}
....
More about loops
Code:
***************************************
Content of this section is hidden, You must be registered and activate your account to see this content. See this link to read how you can remove this limitation:
http://forum.civilea.com/thread-27464.html
***************************************
You can add breakpoints like below:
Visual Studio allows you to run the application step by step in order to see how the code behaves, how variables change values. In loops this is very useful, you can identify mistakes.
In case you're not interested to run the whole program step by step you can add breakpoints by clicking on the left side of the code area, the red bubble in the picture above is obtained like that.
The program will run until a breakpoint is reached, you can click on Continue button (the previous start button) to jump to the next breakpoint or click Debug->Step Into to run it step by step. There's a keyboard shortcut F11.
At the bottom instead of the errors window you can see the Locals.
It contains a list of your variables and their values.
If you move the mouse over variables or operations you can see the current and future values. You can even check i<1000 it will tell you if it's true or false.
You can remove breakpoints the same way you add them.
I hope the reader will find this useful and proceed further.