SlideShare a Scribd company logo
1 of 17
ORGANIZED BY MAJID JHATIAL
JAVA PROGRAMMER
My majid2936@gmail.com
Only for loop exercise and a lot of example in
For loop
Coming soon upload while-loop do-while loop
LOOP REPETITION STATEMENTS
Repetition of statements allow us to
execute a statements multiple time.
Java has three kinds repetition
statements
1 for loop
2 While loop
3 Do-while loop
WHAT IS FOR LOOP ?
For loop is also known as counter loop
There are three part of for loop.
following syntax:
For(initialization ,condition; increment )
1 Initialization is executed once before the loop
begins
2 The statement is executed until the condition
becomes false
3 The increment portion is executed at the end of each
teration
THE FOR STATEMENTS
Example for loop
For(int count=1 ;count<=5; count++){
System.out.println(count);
}
1 Initialization section can be declare the variable
2 Increment section can be performed any calculation
for (int num=100; num > 0; num -= 5){
System.out.println (num);
}
INFINITE LOOP
For example infinite loop
for(int count=1; count<=14; i--){
System.out.println(count);
}
Infinite loop will continue execute until interrupter
(Ctrl-c)
ENDING LOOPING PROGRAM
Break
Break statements result in the terminate of
statements .which applies(Do-while,for,while, switch) . The
break statements gets you out of loop. No meter what the
loop e ending condition. Break immediately says. I am out
here.
Continue
continue skips the statements after the continue
statement and keeps looping.
Continue perform a jump to the next test condition in a loop
the condition statement may be used only in iteration
statements (loop)
THE BREAK
Break example in for loop syntax
for(int i=1; i<=30; i++){ output : 1,2,3
if(i==3){
break;
}
System.out.println(i);
}
Int count=0;
for(int i=1; i<=30; i++){
if(i==16){
break;
}
System.out.println(i);
count++;
}
System.out.println(“Totle=”+count);
CONTINUE EXAMPLE
for(int count=1; count<=30; i++){
if(count==13){
continue;
}
System.out.print(count);
}
int a=0;
for(int count=1; i<=22; count++){
if(count==13){
continue;
}
System.out.oprintln(count);
a++;
}
System.out.println(a);
FIBONACCI SERIES
Enter number 5 then output 1,1,2,3
Scanner ob=new Scanner(System.in);
System.out.println(“Enter the number”);
int i,a=0,b=1,c=0;
int num=ob.nextInt();
for( i=1; i<=num; i++){
System.out.println(c);
a=b;
b=c;
c=a+b;
}
FACTORIAL SERIES
Example factorial number and enter the 5 number t then
output 120..
Scanner bo = new Scanner(System.in);
System.out.println(“Enter the number”);
int fact=1;
int num = ob.nextInt();
for(int i=1; i<=num; i++){
fact=fact*i;
System.out.println(“this factorial number ”+fact);
}
PRIME NUMBER
int n;
int status = 1, num = 3;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the value of n:");
n = scanner.nextInt();
if (n >= 1) {
System.out.println("First "+n+" prime numbers are:");
System.out.println(2); }
for ( int i = 2 ; i <=n ; ) {
for ( int j = 2 ; j <= Math.sqrt(num) ; j++ ) {
if ( num%j == 0 ) {
status = 0;
break; }
}
if ( status != 0){
System.out.println(num);
i++; }
status = 1;
num++; }
NEST FOR LOOP
For loop inside for loop is called nested for loop
A for loop can contain any kind of statement in its body,
including another for loop.
follow syntax
for( outer ){
for(inner){
}
for(----; ---; ){
}
}
practice nest loop
PATRICE NEST LOOP SAME EXAMPLE
class Test{
public static void main(String arg[]){
for(int i=1 ; i=4; i++ ){
f(int j=1; j<=4; j++ ){
}// inner loop close
System.out.println(j);
}// outer loop close;
}
}
another example
for(int i=2 i<5; i++ ){
for(int j=i; j<=5; j++){
System.out.println(i);
}
System.out.println();
}
for( int i=1; i<=10 ; i++){
for(int j=1; j<10; j++ ){
System.out.println(j);
j++;
}
}
for( int i=1; i<=10 ; i++){
for(int j=1; j>10; j++ ){
System.out.println(j);
j++;
}
System.out.println(i);
}
for( int i=1; i>=10 ; i--){
for(int j=1; j<10; j++ ){
System.out.println(j);
j++;
}
}
Nested for loop exercise
What is the output of the following nested for
loop?
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
Output:
*
**
***
****
*****
******
for (int i = 1; i <= 6; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(i);
}
System.out.println();
}
Output?
What is the output of the following nested for loops?
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= (5 - i); j++) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
System.out.print(i);
}
System.out.println();
}
Answer:
1
22
333
4444
55555
This loop repeats 10 times, with i from 1 to 10.
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 5; j++) { // loop goes 5 times
System.out.print(j); // print the j
}
System.out.println();
}
Better:
// Prints 12345 ten times on ten separate lines.
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 5; j++) {
System.out.print(j);
}
System.out.println(); // end the line of output
}

More Related Content

What's hot (20)

Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java History
Java HistoryJava History
Java History
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Loops c++
Loops c++Loops c++
Loops c++
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Chapter 13 - Recursion
Chapter 13 - RecursionChapter 13 - Recursion
Chapter 13 - Recursion
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
OOP java
OOP javaOOP java
OOP java
 
C# loops
C# loopsC# loops
C# loops
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
Files in java
Files in javaFiles in java
Files in java
 
Java threads
Java threadsJava threads
Java threads
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 

Viewers also liked

1426 1001 олимпиадн. и занимат. задачи по математике балаян э.н-2008 -364с
1426  1001 олимпиадн. и занимат. задачи по математике балаян э.н-2008 -364с1426  1001 олимпиадн. и занимат. задачи по математике балаян э.н-2008 -364с
1426 1001 олимпиадн. и занимат. задачи по математике балаян э.н-2008 -364сpsvayy
 
русский язык. справочник 2013 224с
русский язык. справочник 2013  224срусский язык. справочник 2013  224с
русский язык. справочник 2013 224сpsvayy
 
108 грамматика русского языка в таблицах и схемах новичёнок и.к-2008 -96с
108  грамматика русского языка в таблицах и схемах новичёнок и.к-2008 -96с108  грамматика русского языка в таблицах и схемах новичёнок и.к-2008 -96с
108 грамматика русского языка в таблицах и схемах новичёнок и.к-2008 -96сpsvayy
 
744 геометрия за 24 часа жалпанова, калинина, мальянц-2009 -304с
744  геометрия за 24 часа жалпанова, калинина, мальянц-2009 -304с744  геометрия за 24 часа жалпанова, калинина, мальянц-2009 -304с
744 геометрия за 24 часа жалпанова, калинина, мальянц-2009 -304сpsvayy
 
Editie Speciala Alegeri 2016
Editie Speciala Alegeri 2016Editie Speciala Alegeri 2016
Editie Speciala Alegeri 2016Alianta INFONET
 
1065 2 уравнения и нерав. с модулями и метод. их решен.-севрюков, смоляков_2...
1065 2  уравнения и нерав. с модулями и метод. их решен.-севрюков, смоляков_2...1065 2  уравнения и нерав. с модулями и метод. их решен.-севрюков, смоляков_2...
1065 2 уравнения и нерав. с модулями и метод. их решен.-севрюков, смоляков_2...psvayy
 
1230 2 сборник задач по матем. с реш. 8-11кл- п.р. сканави м.и_2012 -624с
1230 2  сборник задач по матем. с реш. 8-11кл- п.р. сканави м.и_2012 -624с1230 2  сборник задач по матем. с реш. 8-11кл- п.р. сканави м.и_2012 -624с
1230 2 сборник задач по матем. с реш. 8-11кл- п.р. сканави м.и_2012 -624сpsvayy
 
761 задачи с параметрами. иррац. уравнения, нерав., системы, задачи с модуле...
761  задачи с параметрами. иррац. уравнения, нерав., системы, задачи с модуле...761  задачи с параметрами. иррац. уравнения, нерав., системы, задачи с модуле...
761 задачи с параметрами. иррац. уравнения, нерав., системы, задачи с модуле...psvayy
 
106 грамотность за 12 занятий. русский язык фролова т.я-2004 -64с
106  грамотность за 12 занятий. русский язык фролова т.я-2004 -64с106  грамотность за 12 занятий. русский язык фролова т.я-2004 -64с
106 грамотность за 12 занятий. русский язык фролова т.я-2004 -64сpsvayy
 
русский язык. весь курс школьн. прогр. в схемах и таблицах 2007 95с
русский язык. весь курс школьн. прогр. в схемах и таблицах 2007  95срусский язык. весь курс школьн. прогр. в схемах и таблицах 2007  95с
русский язык. весь курс школьн. прогр. в схемах и таблицах 2007 95сpsvayy
 
MEDC6000ThesisResearchProject_Lane
MEDC6000ThesisResearchProject_LaneMEDC6000ThesisResearchProject_Lane
MEDC6000ThesisResearchProject_LaneKristina Lane
 
762 задачи с параметрами. примен. свойств функций, преобр. неравенств локоть...
762  задачи с параметрами. примен. свойств функций, преобр. неравенств локоть...762  задачи с параметрами. примен. свойств функций, преобр. неравенств локоть...
762 задачи с параметрами. примен. свойств функций, преобр. неравенств локоть...psvayy
 

Viewers also liked (18)

Java Basics
Java BasicsJava Basics
Java Basics
 
Java Programming: Loops
Java Programming: LoopsJava Programming: Loops
Java Programming: Loops
 
La valla
La vallaLa valla
La valla
 
1426 1001 олимпиадн. и занимат. задачи по математике балаян э.н-2008 -364с
1426  1001 олимпиадн. и занимат. задачи по математике балаян э.н-2008 -364с1426  1001 олимпиадн. и занимат. задачи по математике балаян э.н-2008 -364с
1426 1001 олимпиадн. и занимат. задачи по математике балаян э.н-2008 -364с
 
русский язык. справочник 2013 224с
русский язык. справочник 2013  224срусский язык. справочник 2013  224с
русский язык. справочник 2013 224с
 
108 грамматика русского языка в таблицах и схемах новичёнок и.к-2008 -96с
108  грамматика русского языка в таблицах и схемах новичёнок и.к-2008 -96с108  грамматика русского языка в таблицах и схемах новичёнок и.к-2008 -96с
108 грамматика русского языка в таблицах и схемах новичёнок и.к-2008 -96с
 
744 геометрия за 24 часа жалпанова, калинина, мальянц-2009 -304с
744  геометрия за 24 часа жалпанова, калинина, мальянц-2009 -304с744  геометрия за 24 часа жалпанова, калинина, мальянц-2009 -304с
744 геометрия за 24 часа жалпанова, калинина, мальянц-2009 -304с
 
Pae etapa 4 ejecucion
Pae  etapa 4 ejecucionPae  etapa 4 ejecucion
Pae etapa 4 ejecucion
 
Editie Speciala Alegeri 2016
Editie Speciala Alegeri 2016Editie Speciala Alegeri 2016
Editie Speciala Alegeri 2016
 
1065 2 уравнения и нерав. с модулями и метод. их решен.-севрюков, смоляков_2...
1065 2  уравнения и нерав. с модулями и метод. их решен.-севрюков, смоляков_2...1065 2  уравнения и нерав. с модулями и метод. их решен.-севрюков, смоляков_2...
1065 2 уравнения и нерав. с модулями и метод. их решен.-севрюков, смоляков_2...
 
1230 2 сборник задач по матем. с реш. 8-11кл- п.р. сканави м.и_2012 -624с
1230 2  сборник задач по матем. с реш. 8-11кл- п.р. сканави м.и_2012 -624с1230 2  сборник задач по матем. с реш. 8-11кл- п.р. сканави м.и_2012 -624с
1230 2 сборник задач по матем. с реш. 8-11кл- п.р. сканави м.и_2012 -624с
 
761 задачи с параметрами. иррац. уравнения, нерав., системы, задачи с модуле...
761  задачи с параметрами. иррац. уравнения, нерав., системы, задачи с модуле...761  задачи с параметрами. иррац. уравнения, нерав., системы, задачи с модуле...
761 задачи с параметрами. иррац. уравнения, нерав., системы, задачи с модуле...
 
106 грамотность за 12 занятий. русский язык фролова т.я-2004 -64с
106  грамотность за 12 занятий. русский язык фролова т.я-2004 -64с106  грамотность за 12 занятий. русский язык фролова т.я-2004 -64с
106 грамотность за 12 занятий. русский язык фролова т.я-2004 -64с
 
русский язык. весь курс школьн. прогр. в схемах и таблицах 2007 95с
русский язык. весь курс школьн. прогр. в схемах и таблицах 2007  95срусский язык. весь курс школьн. прогр. в схемах и таблицах 2007  95с
русский язык. весь курс школьн. прогр. в схемах и таблицах 2007 95с
 
MEDC6000ThesisResearchProject_Lane
MEDC6000ThesisResearchProject_LaneMEDC6000ThesisResearchProject_Lane
MEDC6000ThesisResearchProject_Lane
 
Trabajo sena 1
Trabajo sena 1Trabajo sena 1
Trabajo sena 1
 
762 задачи с параметрами. примен. свойств функций, преобр. неравенств локоть...
762  задачи с параметрами. примен. свойств функций, преобр. неравенств локоть...762  задачи с параметрами. примен. свойств функций, преобр. неравенств локоть...
762 задачи с параметрами. примен. свойств функций, преобр. неравенств локоть...
 
Letra Inicial e Imagens
Letra Inicial e ImagensLetra Inicial e Imagens
Letra Inicial e Imagens
 

Similar to for loop in java

Pi j1.4 loops
Pi j1.4 loopsPi j1.4 loops
Pi j1.4 loopsmcollison
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6Vince Vo
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition StructurePRN USM
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)jahanullah
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.pptMahyuddin8
 
First come first serve scheduling algorithm (FCFS) is the process th.pdf
First come first serve scheduling algorithm (FCFS) is the process th.pdfFirst come first serve scheduling algorithm (FCFS) is the process th.pdf
First come first serve scheduling algorithm (FCFS) is the process th.pdfapjewellers
 
Project_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_endsProject_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_ends? ?
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Pythonprimeteacher32
 

Similar to for loop in java (20)

Pi j1.4 loops
Pi j1.4 loopsPi j1.4 loops
Pi j1.4 loops
 
DSA 103 Object Oriented Programming :: Week 3
DSA 103 Object Oriented Programming :: Week 3DSA 103 Object Oriented Programming :: Week 3
DSA 103 Object Oriented Programming :: Week 3
 
Comp102 lec 6
Comp102   lec 6Comp102   lec 6
Comp102 lec 6
 
06.Loops
06.Loops06.Loops
06.Loops
 
Ch5(loops)
Ch5(loops)Ch5(loops)
Ch5(loops)
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
 
Algorithms with-java-1.0
Algorithms with-java-1.0Algorithms with-java-1.0
Algorithms with-java-1.0
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.ppt
 
First come first serve scheduling algorithm (FCFS) is the process th.pdf
First come first serve scheduling algorithm (FCFS) is the process th.pdfFirst come first serve scheduling algorithm (FCFS) is the process th.pdf
First come first serve scheduling algorithm (FCFS) is the process th.pdf
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
 
Project_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_endsProject_Euler_No_104_Pandigital_Fibonacci_ends
Project_Euler_No_104_Pandigital_Fibonacci_ends
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Python
 
Loops
LoopsLoops
Loops
 
Java presentation
Java presentationJava presentation
Java presentation
 
For loop java
For loop javaFor loop java
For loop java
 

Recently uploaded

Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationNathan Young
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptssuser319dad
 
Event 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxEvent 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxaryanv1753
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxJohnree4
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...marjmae69
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxFamilyWorshipCenterD
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...NETWAYS
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...NETWAYS
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸mathanramanathan2005
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Krijn Poppe
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 

Recently uploaded (20)

Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism Presentation
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.ppt
 
Event 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptxEvent 4 Introduction to Open Source.pptx
Event 4 Introduction to Open Source.pptx
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptx
 
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
Gaps, Issues and Challenges in the Implementation of Mother Tongue Based-Mult...
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 

for loop in java

  • 1. ORGANIZED BY MAJID JHATIAL JAVA PROGRAMMER My majid2936@gmail.com Only for loop exercise and a lot of example in For loop Coming soon upload while-loop do-while loop
  • 2. LOOP REPETITION STATEMENTS Repetition of statements allow us to execute a statements multiple time. Java has three kinds repetition statements 1 for loop 2 While loop 3 Do-while loop
  • 3. WHAT IS FOR LOOP ? For loop is also known as counter loop There are three part of for loop. following syntax: For(initialization ,condition; increment ) 1 Initialization is executed once before the loop begins 2 The statement is executed until the condition becomes false 3 The increment portion is executed at the end of each teration
  • 4. THE FOR STATEMENTS Example for loop For(int count=1 ;count<=5; count++){ System.out.println(count); } 1 Initialization section can be declare the variable 2 Increment section can be performed any calculation for (int num=100; num > 0; num -= 5){ System.out.println (num); }
  • 5. INFINITE LOOP For example infinite loop for(int count=1; count<=14; i--){ System.out.println(count); } Infinite loop will continue execute until interrupter (Ctrl-c)
  • 6. ENDING LOOPING PROGRAM Break Break statements result in the terminate of statements .which applies(Do-while,for,while, switch) . The break statements gets you out of loop. No meter what the loop e ending condition. Break immediately says. I am out here. Continue continue skips the statements after the continue statement and keeps looping. Continue perform a jump to the next test condition in a loop the condition statement may be used only in iteration statements (loop)
  • 7. THE BREAK Break example in for loop syntax for(int i=1; i<=30; i++){ output : 1,2,3 if(i==3){ break; } System.out.println(i); } Int count=0; for(int i=1; i<=30; i++){ if(i==16){ break; } System.out.println(i); count++; } System.out.println(“Totle=”+count);
  • 8. CONTINUE EXAMPLE for(int count=1; count<=30; i++){ if(count==13){ continue; } System.out.print(count); } int a=0; for(int count=1; i<=22; count++){ if(count==13){ continue; } System.out.oprintln(count); a++; } System.out.println(a);
  • 9. FIBONACCI SERIES Enter number 5 then output 1,1,2,3 Scanner ob=new Scanner(System.in); System.out.println(“Enter the number”); int i,a=0,b=1,c=0; int num=ob.nextInt(); for( i=1; i<=num; i++){ System.out.println(c); a=b; b=c; c=a+b; }
  • 10. FACTORIAL SERIES Example factorial number and enter the 5 number t then output 120.. Scanner bo = new Scanner(System.in); System.out.println(“Enter the number”); int fact=1; int num = ob.nextInt(); for(int i=1; i<=num; i++){ fact=fact*i; System.out.println(“this factorial number ”+fact); }
  • 11. PRIME NUMBER int n; int status = 1, num = 3; Scanner scanner = new Scanner(System.in); System.out.println("Enter the value of n:"); n = scanner.nextInt(); if (n >= 1) { System.out.println("First "+n+" prime numbers are:"); System.out.println(2); } for ( int i = 2 ; i <=n ; ) { for ( int j = 2 ; j <= Math.sqrt(num) ; j++ ) { if ( num%j == 0 ) { status = 0; break; } } if ( status != 0){ System.out.println(num); i++; } status = 1; num++; }
  • 12. NEST FOR LOOP For loop inside for loop is called nested for loop A for loop can contain any kind of statement in its body, including another for loop. follow syntax for( outer ){ for(inner){ } for(----; ---; ){ } } practice nest loop
  • 13. PATRICE NEST LOOP SAME EXAMPLE class Test{ public static void main(String arg[]){ for(int i=1 ; i=4; i++ ){ f(int j=1; j<=4; j++ ){ }// inner loop close System.out.println(j); }// outer loop close; } } another example for(int i=2 i<5; i++ ){ for(int j=i; j<=5; j++){ System.out.println(i); } System.out.println(); }
  • 14. for( int i=1; i<=10 ; i++){ for(int j=1; j<10; j++ ){ System.out.println(j); j++; } } for( int i=1; i<=10 ; i++){ for(int j=1; j>10; j++ ){ System.out.println(j); j++; } System.out.println(i); } for( int i=1; i>=10 ; i--){ for(int j=1; j<10; j++ ){ System.out.println(j); j++; } }
  • 15. Nested for loop exercise What is the output of the following nested for loop? for (int i = 1; i <= 6; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } Output: * ** *** **** ***** ****** for (int i = 1; i <= 6; i++) { for (int j = 1; j <= i; j++) { System.out.print(i); } System.out.println(); } Output?
  • 16. What is the output of the following nested for loops? for (int i = 1; i <= 5; i++) { for (int j = 1; j <= (5 - i); j++) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(i); } System.out.println(); } Answer: 1 22 333 4444 55555
  • 17. This loop repeats 10 times, with i from 1 to 10. for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 5; j++) { // loop goes 5 times System.out.print(j); // print the j } System.out.println(); } Better: // Prints 12345 ten times on ten separate lines. for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 5; j++) { System.out.print(j); } System.out.println(); // end the line of output }