SlideShare a Scribd company logo
10
Most read
14
Most read
16
Most read
Introduction of basics loop and array
Introduction of basics loop and array
Object Oriented Programming
Presented by:
Naveed Hussain
Presented to:
Mr. Rana Mudassir
Topic:
Basics of Loops and Arrays
Class:
MCS 2nd Semester
Object Oriented Programming
Loops
Array
Loops
• In programming languages , loops
are used to execute a set of
instructions / function
s repeatedly when some conditions
become t rue.
Type s of Loops
For loop
While loop
Do While loop
For loop:
The Java for loop is used to
iterate a part of the program
several times. If the number of
iteration is fixed, it is
recommended to use for loop.
Types of“For Loop”
For each Loop
Simple For Loop
Labeled For Loop
For Loop
Simple For Loop:
The simple for loop is
same as C/C++. We can initialize
variable, check condition and
increment/decrement value.
Syntax:
for(initialization;condition;incr/dec
r)
{
//code to be executed
}
For each Loop:
The for-each loop is used to traverse
array or collection in java. It is easier to use than simple
for loop because we don't need to increment value and
use subscript notation.
It works on elements basis not index. It returns element
one by one in the defined variable.
Syntax:
for(Type var:array)
{
//code to be executed
}
Labeled For Loop:
We can have name of each for loop.
To do so, we use label before the for loop. It is useful if
we have nested for loop so that we can break/continue
specific for loop. “Normally, break and continue
keywords breaks/continues the inner most for loop only”.
Syntax:
labelname:
for(initialization;condition;incr/decr)
{
//code to be executed
}
While Loop:
The Java while loop is
used to iterate a part of the
program several times. If the
number of iteration is not fixed,it is
recommended to use while loop.
Syntax:
while(condition)
{
//code to be executed
i++/i--;
}
Do-While Loop:
If the number of iteration is not fixed
and you must have to execute the
loop at least once, it is recommended
to use do-while loop.The Java do-
while loop is executed at least once
because condition is checked after
loop body.
Syntax:
do
{
//code to be executed
}
while(condition);
Introduction of basics loop and array
Array:
 Array is an object the contains elements of similar
data type.
 Stores similar elements.
 Stores fixed set of elements in array.
Single Dimensional
Array
Click Multi-Dimensional
Array
Arrays
Single Dimensional Array:
One dimensional array is a list of same typed
variables. To create an array, first you must declare an
array variable of required type.
Syntax of Declare an Array:
 DataType[] arr;
 DataType []arr;
 DataType arr[];
Exapmle:
int a[]=new int[5];//declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
Multi-Dimensional Array:
The arrays you have been
using so far have only held one column of data. But you
can set up an array to hold more than one column.
These are called multi-dimensional arrays.
Syntax to Declare:
 dataType[][] arrayRefVar;
 dataType [][]arrayRefVar;
 dataType arrayRefVar[][];
 dataType []arrayRefVar[];
Example:
int[][] arr=new int[2][2];//2 row and 2 column
arr[0][0]=1;
arr[0][1]=2;
arr[1][2]=3;
arr[1][3]=4;
Introduction of basics loop and array

More Related Content

PPTX
Looping statements in C
PPTX
Loops in c language
PPTX
Loops in C Programming Language
PDF
Loops and conditional statements
PPTX
Loops in c programming
PPTX
Loops in C Programming
PPTX
The Loops
Looping statements in C
Loops in c language
Loops in C Programming Language
Loops and conditional statements
Loops in c programming
Loops in C Programming
The Loops

What's hot (20)

PPTX
ODP
Drilling the Async Library
PPTX
Advanced Javascript
PPTX
Mule java part-3
PPTX
Mule java part-3
PPTX
Java in mule part 3
PPTX
Mule java part-4
PPTX
Testing in Scala. Adform Research
PPTX
JS - Basics
PPTX
JavaScript Basics
ODP
Getting started with typescript and angular 2
PPTX
Introduction to Scala language
PPTX
PHP Basics
PPTX
Lambda Expressions in Java 8
ODP
Shapeless- Generic programming for Scala
ODP
Can't Dance The Lambda
PDF
Swift, a quick overview
PPTX
002. Introducere in type script
PPTX
Lecture 5 javascript
PPTX
Introduction to JavaScript
Drilling the Async Library
Advanced Javascript
Mule java part-3
Mule java part-3
Java in mule part 3
Mule java part-4
Testing in Scala. Adform Research
JS - Basics
JavaScript Basics
Getting started with typescript and angular 2
Introduction to Scala language
PHP Basics
Lambda Expressions in Java 8
Shapeless- Generic programming for Scala
Can't Dance The Lambda
Swift, a quick overview
002. Introducere in type script
Lecture 5 javascript
Introduction to JavaScript
Ad

Similar to Introduction of basics loop and array (20)

PPT
Javatut1
PPT
Java tut1 Coderdojo Cahersiveen
PPT
Java tut1
PPT
Java tut1
PPT
Java Tutorial
PPT
Java_Tutorial_Introduction_to_Core_java.ppt
PPTX
JAVA LOOP.pptx
PPT
Java teaching ppt for the freshers in colleeg.ppt
PPSX
Java Tutorial
PPT
Java Tutorial | My Heart
PPT
Java tutorial PPT
PPT
Java tutorial PPT
ODP
Synapseindia reviews.odp.
PPT
Tutorial java
PPT
Java Tutorial
PPT
Java tut1
PPT
Java Tut1
PDF
LECTURE 3 LOOPS, ARRAYS.pdf
PPTX
Arrays in programming
Javatut1
Java tut1 Coderdojo Cahersiveen
Java tut1
Java tut1
Java Tutorial
Java_Tutorial_Introduction_to_Core_java.ppt
JAVA LOOP.pptx
Java teaching ppt for the freshers in colleeg.ppt
Java Tutorial
Java Tutorial | My Heart
Java tutorial PPT
Java tutorial PPT
Synapseindia reviews.odp.
Tutorial java
Java Tutorial
Java tut1
Java Tut1
LECTURE 3 LOOPS, ARRAYS.pdf
Arrays in programming
Ad

Recently uploaded (20)

PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
Microbial diseases, their pathogenesis and prophylaxis
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Supply Chain Operations Speaking Notes -ICLT Program
master seminar digital applications in india
Classroom Observation Tools for Teachers
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Computing-Curriculum for Schools in Ghana
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
What if we spent less time fighting change, and more time building what’s rig...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Yogi Goddess Pres Conference Studio Updates
Chinmaya Tiranga quiz Grand Finale.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Weekly quiz Compilation Jan -July 25.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
2.FourierTransform-ShortQuestionswithAnswers.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Microbial diseases, their pathogenesis and prophylaxis

Introduction of basics loop and array

  • 3. Object Oriented Programming Presented by: Naveed Hussain Presented to: Mr. Rana Mudassir Topic: Basics of Loops and Arrays Class: MCS 2nd Semester
  • 6. • In programming languages , loops are used to execute a set of instructions / function s repeatedly when some conditions become t rue.
  • 7. Type s of Loops For loop While loop Do While loop
  • 8. For loop: The Java for loop is used to iterate a part of the program several times. If the number of iteration is fixed, it is recommended to use for loop.
  • 9. Types of“For Loop” For each Loop Simple For Loop Labeled For Loop For Loop
  • 10. Simple For Loop: The simple for loop is same as C/C++. We can initialize variable, check condition and increment/decrement value. Syntax: for(initialization;condition;incr/dec r) { //code to be executed }
  • 11. For each Loop: The for-each loop is used to traverse array or collection in java. It is easier to use than simple for loop because we don't need to increment value and use subscript notation. It works on elements basis not index. It returns element one by one in the defined variable. Syntax: for(Type var:array) { //code to be executed }
  • 12. Labeled For Loop: We can have name of each for loop. To do so, we use label before the for loop. It is useful if we have nested for loop so that we can break/continue specific for loop. “Normally, break and continue keywords breaks/continues the inner most for loop only”. Syntax: labelname: for(initialization;condition;incr/decr) { //code to be executed }
  • 13. While Loop: The Java while loop is used to iterate a part of the program several times. If the number of iteration is not fixed,it is recommended to use while loop. Syntax: while(condition) { //code to be executed i++/i--; }
  • 14. Do-While Loop: If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use do-while loop.The Java do- while loop is executed at least once because condition is checked after loop body. Syntax: do { //code to be executed } while(condition);
  • 16. Array:  Array is an object the contains elements of similar data type.  Stores similar elements.  Stores fixed set of elements in array.
  • 18. Single Dimensional Array: One dimensional array is a list of same typed variables. To create an array, first you must declare an array variable of required type.
  • 19. Syntax of Declare an Array:  DataType[] arr;  DataType []arr;  DataType arr[]; Exapmle: int a[]=new int[5];//declaration and instantiation a[0]=10;//initialization a[1]=20; a[2]=70; a[3]=40; a[4]=50;
  • 20. Multi-Dimensional Array: The arrays you have been using so far have only held one column of data. But you can set up an array to hold more than one column. These are called multi-dimensional arrays.
  • 21. Syntax to Declare:  dataType[][] arrayRefVar;  dataType [][]arrayRefVar;  dataType arrayRefVar[][];  dataType []arrayRefVar[]; Example: int[][] arr=new int[2][2];//2 row and 2 column arr[0][0]=1; arr[0][1]=2; arr[1][2]=3; arr[1][3]=4;