2/1/2022

While Loop In Sequence Diagram

Diagram used without permission from. Sequence describes the specific order in which commands are written and executed. The computer does not read all of the steps and then determine the correct order. The programmer has to determine the correct order. The computer will perform the instructions one at a time, in the order in which they are.

  1. How To Show While Loop In Sequence Diagram
  2. While Loop In Sequence Diagram Example
  3. While Loop In Sequence Diagram Using
  4. Sequence Diagrams Examples
  5. While Loop In Sequence Diagram Template

Sequence Diagrams

A sequence diagram is a form of interaction diagram which shows objects as lifelines running down the page, with their interactions over time represented as messages drawn as arrows from the source lifeline to the target lifeline. Sequence diagrams are good at showing which objects communicate with which other objects; and what messages trigger those communications. Sequence diagrams are not intended for showing complex procedural logic.

Sequence diagram of a hospital management system. Technology has completely transformed the field of medicine, as it has with most industries. A hospital information system, also known as a hospital information system, helps doctors, administrators, and hospital staff managing all of the activities and information collected at a hospital, including checkups, prescriptions, appointments,. UML sequence diagram combined fragment is an interaction fragment which defines a combination (expression) of interaction fragments, it is defined by an interaction operator and corresponding interaction operands - alternative, option, loop, break, parallel, strict sequencing, weak sequencing, critical region, ignore, consider, assert, negative.


Lifelines

A lifeline represents an individual participant in a sequence diagram. A lifeline will usually have a rectangle containing its object name. If its name is 'self', that indicates that the lifeline represents the classifier which owns the sequence diagram.

Sometimes a sequence diagram will have a lifeline with an actor element symbol at its head. This will usually be the case if the sequence diagram is owned by a use case. Boundary, control and entity elements from robustness diagrams can also own lifelines.


Sequence

Messages

Messages are displayed as arrows. Messages can be complete, lost or found; synchronous or asynchronous; call or signal. In the following diagram, the first message is a synchronous message (denoted by the solid arrowhead) complete with an implicit return message; the second message is asynchronous (denoted by line arrowhead), and the third is the asynchronous return message (denoted by the dashed line).


Execution Occurrence

A thin rectangle running down the lifeline denotes the execution occurrence, or activation of a focus of control. In the previous diagram, there are three execution occurrences. The first is the source object sending two messages and receiving two replies; the second is the target object receiving a synchronous message and returning a reply; and the third is the target object receiving an asynchronous message and returning a reply.

While Loop In Sequence Diagram

Self Message

A self message can represent a recursive call of an operation, or one method calling another method belonging to the same object. It is shown as creating a nested focus of control in the lifeline’s execution occurrence.


Lost and Found Messages

Lost messages are those that are either sent but do not arrive at the intended recipient, or which go to a recipient not shown on the current diagram. Found messages are those that arrive from an unknown sender, or from a sender not shown on the current diagram. They are denoted going to or coming from an endpoint element.


Sequence

Lifeline Start and End

A lifeline may be created or destroyed during the timescale represented by a sequence diagram. In the latter case, the lifeline is terminated by a stop symbol, represented as a cross. In the former case, the symbol at the head of the lifeline is shown at a lower level down the page than the symbol of the object that caused the creation. The following diagram shows an object being created and destroyed.


While Loop In Sequence Diagram

Duration and Time Constraints

By default, a message is shown as a horizontal line. Since the lifeline represents the passage of time down the screen, when modelling a real-time system, or even a time-bound business process, it can be important to consider the length of time it takes to perform actions. By setting a duration constraint for a message, the message will be shown as a sloping line.


How To Show While Loop In Sequence Diagram

Combined Fragments

It was stated earlier that sequence diagrams are not intended for showing complex procedural logic. While this is the case, there are a number of mechanisms that do allow for adding a degree of procedural logic to diagrams and which come under the heading of combined fragments. A combined fragment is one or more processing sequence enclosed in a frame and executed under specific named circumstances. The fragments available are:
  • Alternative fragment (denoted “alt”) models if…then…else constructs.
  • Option fragment (denoted “opt”) models switch constructs.
  • Break fragment models an alternative sequence of events that is processed instead of the whole of the rest of the diagram.
  • Parallel fragment (denoted “par”) models concurrent processing.
  • Weak sequencing fragment (denoted “seq”) encloses a number of sequences for which all the messages must be processed in a preceding segment before the following segment can start, but which does not impose any sequencing within a segment on messages that don’t share a lifeline.
  • Strict sequencing fragment (denoted “strict”) encloses a series of messages which must be processed in the given order.
  • Negative fragment (denoted “neg”) encloses an invalid series of messages.
  • Critical fragment encloses a critical section.
  • Ignore fragment declares a message or message to be of no interest if it appears in the current context.
  • Consider fragment is in effect the opposite of the ignore fragment: any message not included in the consider fragment should be ignored.
  • Assertion fragment (denoted “assert”) designates that any sequence not shown as an operand of the assertion is invalid.
  • Loop fragment encloses a series of messages which are repeated.
The following diagram shows a loop fragment.

While Loop In Sequence Diagram Example

There is also an interaction occurrence, which is similar to a combined fragment. An interaction occurrence is a reference to another diagram which has the word 'ref' in the top left corner of the frame, and has the name of the referenced diagram shown in the middle of the frame.


Gate

A gate is a connection point for connecting a message inside a fragment with a message outside a fragment. EA shows a gate as a small square on a fragment frame. Diagram gates act as off-page connectors for sequence diagrams, representing the source of incoming messages or the target of outgoing messages. The following two diagrams show how they might be used in practice. Note that the gate on the top level diagram is the point at which the message arrowhead touches the reference fragment - there is no need to render it as a box shape.

While Loop In Sequence Diagram Using


Part Decomposition

An object can have more than one lifeline coming from it. This allows for inter- and intra-object messages to be displayed on the same diagram.


State Invariant / Continuations

Sequence Diagrams Examples

A state invariant is a constraint placed on a lifeline that must be true at run-time. It is shown as a rectangle with semi-circular ends.

A continuation has the same notation as a state invariant, but is used in combined fragments and can stretch across more than one lifeline.

Loop

While Loop In Sequence Diagram Template

Java Resources‎ > ‎

Basic Programming Logic (SSR)

Contents

  1. 3 Selection
    1. 3.1 Examples:
    2. 3.2 Boolean Conditions
  2. 4 Repetition
    1. 4.1 Counted - For Loops
    2. 4.3 While Loop
    3. 4.4 Do-While Loop

The three basic structures in programming logic are:
  • SEQUENCE - or Sequential Logic
  • SELECTION - or Conditional Logic
  • REPETITION - or Iterative Logic
All problems can be solved by writing algorithms using only these 3 logic structures. These structures can be combined in an infinite number of ways - the more complex problems requiring a more complex combination.
Diagram used without permission from https://www3.ntu.edu.sg/home/ehchua/programming/cpp/cp1_Basics.html

Sequence describes the specific order in which commands are written and executed. The computer does not read all of the steps and then determine the correct order. The programmer has to determine the correct order. The computer will perform the instructions one at a time, in the order in which they are written.
Compare the following two algorithms for brushing teeth:
  • Pick up toothbrush
  • Put toothpaste on toothbrush
  • Brush teeth
  • Rinse toothbrush
  • Put away toothbrush
  • Pick up toothbrush
  • Brush teeth
  • Put toothpaste on toothbrush
  • Rinse toothbrush
  • Put away toothbrush
Diagram used without permission from http://www.ntu.edu.sg
Each algorithm has the same 5 steps but in a different order. In the 2nd algorithm, the teeth would be brushed without toothpaste, the toothpaste would be put on after brushing, then wasted as it is rinsed away. A human might read all of the steps and then determine the correct order to complete them, but a computer will not. It will complete the steps in the order they are given. For this reason, the sequence of the steps is very important!


Selection or Conditional Logic is similar to making a decision based on certain conditions.

Examples:

  • if it is cold outside, wear a coat
  • if customer has a membership card, apply discount
  • if student is under 12, the cost is $5; otherwise cost is $8

Syntax:

else
c.println ('Your ticket will cost $10.');

Diagram used without permission from https://www3.ntu.edu.sg


Notes:
  • The computer will only look at the statements in an else block if the first condition is false.
  • You can include as many else if statements as you need, but the first statement must be just if, and if you use an else alone it must be last.

Boolean Conditions

A boolean condition must have a value of true or false.
  • true (iNum has a value that is less than 7)
  • or false (iNum is not less than 7)
The following operators can be used to compare primitive data types (i.e.: int, double, char - not Strings or other classes).
Java OperatorMeaning
equal to
!=not equal to
<less than
<=less than or equal to
>greater than
>=greater than or equal to
or
&and

Comparisons using boolean values

boolean values only have 2 states, so < and > are meaningless.
if (b true) is redundant. if (b) works just as well. Remember, the whole condition has a boolean value.
if (b false) can be replaced with if (!b) - !b means not b (i.e.: b is not true, hence it must be false)

Comparing Strings

String variables are instances of the String class, so they cannot be compared like the primitive data types.
To compare two Strings, we must use the .equals(), the .equalsIgnoreCase(), or the .compareTo() methods. (See the String class documentation.)
eg: if (sName.equals('Fred')) NOT if (sName 'Fred')
Note: the (sName 'Fred') won't give you an error, it just won't work.



Repetition or Iterative Logic describes what is commonly called a Loop. A group of commands is repeated until a certain condition is met.
Loops commonly have 2 forms - counted and conditional.

Counted - For Loops

We use a counted loop when we know how many times to repeat. In Java, these are known as for loops.

Syntax

{
}

Example

Roll a single dice object 5 times.
{
c.println ('You rolled a ' + myDice.getNumber () );

Used without permission from https://www3.ntu.edu.sg


Conditional (Uncounted) - While (& Do-While) Loops

We use a conditional loop when we do not know how many times the loop will repeat. In Java, these are known as while (and do-while) loops.

While Loop

Syntax

{
}

Example:

c.print ('Enter your mark: ');
while (mark < 0 mark > 100)
c.print ('Invalid mark. Please re-enter: ');
}



Used without permission from https://www3.ntu.edu.sg

Do-While Loop

Syntax

do
body
while (test);

Example

do
myDice.roll ();
c.println ('You rolled a ' + myDice.getNumber () );
c.println ('Press any key to roll again or 'q' to quit.');
}



Used without permission from https://www3.ntu.edu.sg