Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been looking around on the internet and have not found a good answer yet. If anyone could be so kind and supply a code sample I would greatly appreciate it. I apologize for the simplicity of the question.

share|improve this question
up vote 4 down vote accepted

This is the simplest one of all: it's when your instructions are executed in the same order that they appear in your program, without repeating or skipping any instructions from the sequence.

For example, this is sequential execution:

int a = 5;
int b = 12;
int c = a*a + b + 7;

On the other hand, this is not sequential execution, because one instruction is going to be skipped.

int a = 5;
int b = 12;
int c;
if (a > b) {
    c = a;
} else {
    c = b;
share|improve this answer
That is actually still sequential. Not because the code takes a branch it isn't sequential. – MDeSchaepmeester Apr 14 '12 at 21:41
@MarioDeSchaepmeester That is not what I learned back when flow charts were still used. Here is an explanation similar to what I heard back in school. – dasblinkenlight Apr 14 '12 at 21:47
From the program's point of view, execute a step, make a choice and execute another step is just 3 steps done sequentially... have a look at this – MDeSchaepmeester Apr 14 '12 at 21:53
@DeSchaepmeester There are two separate contexts where "sequential execution" can be used - as in "sequential vs. conditonal vs. loop", or as in "sequential vs. concurrent". The question does not specify enough context to decide conclusively one or the other, but since the OP asked for a code snippet, I decided that he did not ask for concurrent vs. sequential. Of course I could be wrong. – dasblinkenlight Apr 14 '12 at 23:03

Sequential code means that it is accessed by a single thread. This means that a single thread can only do code in a specific order, hence it being sequential. The other thing is concurrent code, multiple threads may access the same code synchronously. The programming needs special care put in to it, as multi-threading can pose security risks and inconsistency risks.

share|improve this answer

protected by Thomas Owens Oct 2 '13 at 13:49

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.