You are on page 1of 19

EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED

QUALITY MANAGEMENT SYSTEM


City of Dasmariñas,Cavite

Loops

Reference:
- Sandeep Nagar, Introduction to Scilab For Engineers and Scientists

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.1 Introduction

When a particular numerical task needs to be “repeated” over different


data points, digital computers become a useful tool since they can perform
this action with greater speeds than humans. Loops perform exactly this
task.
Using a condition to check the start and termination rules, users can
perform repetitive parts of a process as desired. Different programming
languages and environments have different rules for defining loops.
Scilab provides a simple way to define and run loops. In addition to loops,
functions also define an important part of modern programming
architecture.
A big program may require a set of instructions to be called at different
times. Hence, this set of instructions can be defined as a subprogram, which
can be requested to perform the computation at a desired time
VIRTUE EXCELLENCE SERVICE
EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.1 Introduction

In this way, a complicated task can be divided into many small parts. This
architecture of programming is called modular programming.
It is the most popular way of programming since it is quite logical, good at
visualizing the problem, and easy to debug.
The most popular way of defining these small sets of instructions is to
define them as functions.
Together, functions and loops break a numerical computation problem into
a series of simpler problems that can be accessed as required.
 In this chapter, we will discuss both of these concepts in detail.

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2 Loops

Loops form an essential part of an algorithm since they perform the tasks
that computers perform best: doing repetitive actions in a very fast manner.
Loops can come in many flavors such as for loop, which repeats certain
tasks over a list of variable values; while loop, which checks a logical
condition before executing a certain task; and if-then-else loop, which
checks a condition and directs the flow of an algorithm.
The loop you choose depends on the problem at hand.
A variety of functions and their usage are described in the following
sections.
Judging their usage critically becomes supremely important because the
looping part of an algorithm consumes most of the execution time.

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2 Loops

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.1 while

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.1 while

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.1 while

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.2 Infinite Loops

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.2 Infinite Loops

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.3 for

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.3 for

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.3 for

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.4 if-elseif-else

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.4 if-elseif-else

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.4 if-elseif-else

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.4 if-elseif-else

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

6.2.4 if-elseif-else

VIRTUE EXCELLENCE SERVICE


EMILIO AGUINALDO COLLEGE ISO 9001: 2015 CERTIFIED
QUALITY MANAGEMENT SYSTEM
City of Dasmariñas,Cavite

Thank you for listening


God Bless

VIRTUE EXCELLENCE SERVICE

You might also like