Pascal question

  • Thread starter C0nfused
  • Start date
  • #1
139
0
Hi everybody,
I am new in programming. I just want to ask this: when we write a program the statements are executed in the order that we have written them in the body of the program? This is about Pascal but does it apply to other languages too? Of course some statements "change the order" causing some to be executed more than once or not at all ("while" loop etc) but generally the order we write them is the order that are executed? And only one statement is executed at a time and not two for example simultaneously?
Thanks
 

Answers and Replies

  • #2
1,430
6
C0nfused said:
Hi everybody,
I am new in programming. I just want to ask this: when we write a program the statements are executed in the order that we have written them in the body of the program? This is about Pascal but does it apply to other languages too? Of course some statements "change the order" causing some to be executed more than once or not at all ("while" loop etc) but generally the order we write them is the order that are executed? And only one statement is executed at a time and not two for example simultaneously?
Thanks


I would hope so, otherwise program writing would be incredibly difficult.

That means yes.
 
  • #3
139
0
Thanks for your answer. Just one more thing: every statement(except for the statements in the loops and the statements in the "if" statement) is only executed once and then the pc goes to the next statement, executes it once and goes on until it reaches the end of the program?
These may be too easy for most of you but i just want to get the basics of how a program operates in a pc
Thanks again
 
  • #4
dduardo
Staff Emeritus
1,891
3
Actually, statements can run simultaneously in some cases. For example, if your writing a multi-threaded application you can fork a process and run another piece of code concurrently. Another case is in an an event driven system. If two or more events are triggered simultaneously, the code for the events will run together. Finally, programming langauges like VHDL, which is used to design hardware, allows procedures to run simultaneously. If this wasn't the case, digital chips would run very slow.
 
  • #5
139
0
Thanks for your answer, but I must admit i didn't understand much. My question
"every statement(except for the statements in the loops and the statements in the "if" statement) is only executed once and then the pc goes to the next statement, executes it once and goes on until it reaches the end of the program?"
is for simple programs made in Pascal! And I would like to know what is going on in such programs.
Thanks anyway
 
  • #6
1,430
6
C0nfused said:
Thanks for your answer, but I must admit i didn't understand much. My question
"every statement(except for the statements in the loops and the statements in the "if" statement) is only executed once and then the pc goes to the next statement, executes it once and goes on until it reaches the end of the program?"
is for simple programs made in Pascal! And I would like to know what is going on in such programs.
Thanks anyway


The things that dduardo mentioned are more advanced concepts. For the things it sounds like you'd be doing, you don't need to worry about it really. Unless you specify otherwise, the program will execute in the order the program is written.
 
  • #7
15
0
In most cases a statement will only be executed once. However, the order can change when using conditionals (if, else, etc). Also, loops (for, while) will execute the same code more than once, usually with some sort of a modification: ie:
for (int i = 0; i < 5; i++) where i is being incremented by for each iteration

And functions can be called multiple times.


Ryan
 
  • #8
139
0
Thanks for your answers. They were really helpful
 
  • #9
139
0
And one more thing that i forgot: when we "call" a procedure in the body of a program ,is it considered as an execution of a statement? In other words, procedure call is a statement, which is executed like all other statements, and when executed, all the statements in the body of the procedure are executed (similar to the way the main program statements are executed) and after that, the program continues normally with the statements in the main body?
Thanks again
 
  • #10
1,430
6
C0nfused said:
And one more thing that i forgot: when we "call" a procedure in the body of a program ,is it considered as an execution of a statement? In other words, procedure call is a statement, which is executed like all other statements, and when executed, all the statements in the body of the procedure are executed (similar to the way the main program statements are executed) and after that, the program continues normally with the statements in the main body?
Thanks again

In a word, yes.
 

Related Threads on Pascal question

  • Last Post
Replies
5
Views
6K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
3
Views
16K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
7
Views
2K
  • Last Post
Replies
7
Views
2K
  • Last Post
Replies
9
Views
2K
Top