Pascal: Order of Execution of Program Statements

  • Thread starter Thread starter C0nfused
  • Start date Start date
  • Tags Tags
    Pascal
Click For Summary

Discussion Overview

The discussion revolves around the order of execution of program statements in Pascal, with implications for other programming languages. Participants explore basic programming concepts, including sequential execution, loops, conditionals, and procedure calls, primarily focusing on how these elements affect the flow of a program.

Discussion Character

  • Exploratory
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • Some participants propose that statements in a program are generally executed in the order they are written, with exceptions for loops and conditionals that can alter this flow.
  • Others argue that in multi-threaded applications or event-driven systems, statements can run simultaneously, which complicates the notion of sequential execution.
  • A participant questions whether every statement, except those in loops or conditionals, is executed only once before moving to the next statement, seeking clarity on basic program operation.
  • It is noted that procedure calls are considered statements and, when executed, run all statements within the procedure before returning to the main program flow.
  • Some participants express confusion about advanced concepts and emphasize a desire to understand the basics of simple Pascal programs.

Areas of Agreement / Disagreement

Participants generally agree that statements are executed in the order written, barring loops and conditionals. However, there is disagreement regarding the execution of statements in multi-threaded contexts and the implications of procedure calls, indicating multiple competing views remain.

Contextual Notes

Limitations include the varying interpretations of execution order in different programming paradigms and the potential for confusion among beginners regarding advanced concepts versus basic programming principles.

C0nfused
Messages
139
Reaction score
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
 
Computer science news on Phys.org
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.
 
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
 
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 languages 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.
 
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
 
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.
 
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
 
Thanks for your answers. They were really helpful
 
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
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
6
Views
4K
Replies
6
Views
5K
Replies
21
Views
5K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K