SlideShare a Scribd company logo
1 of 16
Basic Operators and Loop
Control in Java.
•Arithmetic Operators?.
•Logical Operators?.
•Relational Operators?.
•Bit wise Operators?.
•Assignment Operators?.
•For, while, do whole loop in java?
•Break and Continue Statements?
4/10/2019 1Jamsher Bhanbhro(F16CS11)
Basic Operators
• Arithmetic Operators: These are same which are
used in mathematical expressions.
• These are (+,-,*,/,%,++,--).
• Relational Operators: These are used to relate
expressions methomatically
• These are (==, >=, <=, >, <, !=) used in java.
• Bitwise Operator: Operations performed on bits
• These are (&’bitwise AND’, II’or’, ^’XOR’,
<<‘LEFTSHIFT’, >>’rightshift’, >>>’zeroshift’ ).
4/10/2019 Jamsher Bhanbhro(F16CS11) 2
Basic Operators.
• Logical Operators: These are used when
there are two condition in a statement.
• These are (&&, II, !).
• Assignment Operators: These are operators
which are used to assign the values.
• These are(=,=+, -=, *=, /=, %=,<<=, >>=)
4/10/2019 Jamsher Bhanbhro(F16CS11) 3
Write a program to demonstrate all
basic operators in java.
4/10/2019 Jamsher Bhanbhro(F16CS11) 4
Program Cont…
• Guess the output of the above program.
• Note: Write a program to use all the types of
each basic operator.
4/10/2019 Jamsher Bhanbhro(F16CS11) 5
Loops
• Loops are used to execute a code of block for several times.
• A loop Consists of a conditional code and a condition.
• The code of block will run till the condition is true.
There are three loops in java.
If true
else
4/10/2019 Jamsher Bhanbhro(F16CS11) 6
Condition Execute
Code
1. While Loop
• Continues or execute the code till the condition
is true.
• Tests condition before executing the code.
• Syntax: while(condition){}
• E.g: int a=4, b=11;
while(b<12){
System.out.println(“output=”+(a+b));
}
4/10/2019 Jamsher Bhanbhro(F16CS11) 7
While Syntax
While(bool exp)
if true
else
4/10/2019 Jamsher Bhanbhro(F16CS11) 8
Condition
Boolean
Expression
Execute
Code
2. For Loop
• Executes the code multiple times
• Approximately same as while but there is some
difference.
• In this loop we will give initialization, condition
and increment values.
• for(init, cond, update){code body}
e.g: int a=11;
for(int i=0; i<=a; i++){
System.out.println(“Hello”);
}
4/10/2019 Jamsher Bhanbhro(F16CS11) 9
For Syntax
While(bool exp)
if true
else incr
4/10/2019 Jamsher Bhanbhro(F16CS11) 10
Condition
Boolean
Expression
Execute
Code
Update
Cond
3. Do While Loop
• Same as while loop but..
• Executes at least once without checking
condition.
• do{}while(cond)
int a=1, b=3;
do{
System.out.println(a*b);
}while(a!=b)
4/10/2019 Jamsher Bhanbhro(F16CS11) 11
3. Do Syntax
While(bool exp)
if true
else
4/10/2019 Jamsher Bhanbhro(F16CS11) 12
Condition
Boolean
Expression
Execute
Code
Why Loops are used write the
advantages.
• Loops are used to reduce the code.
• Loops provide flexibility to the code.
• Loops are highly used in the programming
specially when we are related with arrays.
• Although it is very important to remember the
syntax and the phenomenon of the loops
structures.
4/10/2019 Jamsher Bhanbhro(F16CS11) 13
Break and Continue Statements
• When the break statement is encountered inside a
loop.
• It breaks the statement and gives the current flow
to the next level.
• Switch() in the cases this break is used.
Eg: int a=11;
if(a>10){
break;
}
4/10/2019 Jamsher Bhanbhro(F16CS11) 14
Continue Statement
• Continue statement is used when we want to continue our
block of code.
• Used for jumping purpose.
• In the for loop continue is used to jump to update statement.
• In while continue used to jump to a Boolean expression.
• Syntax: continue;
int a=15;
if(a>11){
continue;
}
4/10/2019 Jamsher Bhanbhro(F16CS11) 15
Tasks
Write a program to draw shape of
• Triangle
• Rectangle
• Pyramid
• Diamond
• Write a program to make a simple calculator of
at least six functions using break and continue
statement.
4/10/2019 Jamsher Bhanbhro(F16CS11) 16

More Related Content

What's hot

RSpec and Rails
RSpec and RailsRSpec and Rails
RSpec and RailsAlan Hecht
 
The Final Programming Project
The Final Programming ProjectThe Final Programming Project
The Final Programming ProjectSage Jacobs
 
Exception handling in c
Exception handling in cException handling in c
Exception handling in cMemo Yekem
 
Unit Testing Front End JavaScript
Unit Testing Front End JavaScriptUnit Testing Front End JavaScript
Unit Testing Front End JavaScriptFITC
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macrosAnand Kumar
 

What's hot (10)

TDD, BDD, RSpec
TDD, BDD, RSpecTDD, BDD, RSpec
TDD, BDD, RSpec
 
Clean Code
Clean CodeClean Code
Clean Code
 
RSpec and Rails
RSpec and RailsRSpec and Rails
RSpec and Rails
 
The Final Programming Project
The Final Programming ProjectThe Final Programming Project
The Final Programming Project
 
Exception handling in c
Exception handling in cException handling in c
Exception handling in c
 
Kelompok 8 Pbw
Kelompok 8 PbwKelompok 8 Pbw
Kelompok 8 Pbw
 
Kelompok 8 Pbw
Kelompok 8 PbwKelompok 8 Pbw
Kelompok 8 Pbw
 
Rtt preso
Rtt presoRtt preso
Rtt preso
 
Unit Testing Front End JavaScript
Unit Testing Front End JavaScriptUnit Testing Front End JavaScript
Unit Testing Front End JavaScript
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 

Similar to Lect7

What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web DevsRami Sayar
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsIt Academy
 
c++ Lecture 3
c++ Lecture 3c++ Lecture 3
c++ Lecture 3sajidpk92
 
Fitc whats new in es6 for web devs
Fitc   whats new in es6 for web devsFitc   whats new in es6 for web devs
Fitc whats new in es6 for web devsFITC
 
c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and SelectionAhmed Nobi
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic OperatorsOperators in Python Arithmetic Operators
Operators in Python Arithmetic Operatorsramireddyobulakondar
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statementsVladislav Hadzhiyski
 
02 Java Language And OOP PART II
02 Java Language And OOP PART II02 Java Language And OOP PART II
02 Java Language And OOP PART IIHari Christian
 
control statements
control statementscontrol statements
control statementsAzeem Sultan
 
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsFunctional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsLeonardo Borges
 
Chapter 3:Programming with Java Operators and Strings
Chapter 3:Programming with Java Operators and  StringsChapter 3:Programming with Java Operators and  Strings
Chapter 3:Programming with Java Operators and StringsIt Academy
 
Chapter 3 : Programming with Java Operators and Strings
Chapter 3 : Programming with Java Operators and  StringsChapter 3 : Programming with Java Operators and  Strings
Chapter 3 : Programming with Java Operators and StringsIt Academy
 
chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)It Academy
 

Similar to Lect7 (20)

What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
Java unit 3
Java unit 3Java unit 3
Java unit 3
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
c++ Lecture 3
c++ Lecture 3c++ Lecture 3
c++ Lecture 3
 
Fitc whats new in es6 for web devs
Fitc   whats new in es6 for web devsFitc   whats new in es6 for web devs
Fitc whats new in es6 for web devs
 
c++ Data Types and Selection
c++ Data Types and Selectionc++ Data Types and Selection
c++ Data Types and Selection
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic OperatorsOperators in Python Arithmetic Operators
Operators in Python Arithmetic Operators
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
 
02 Java Language And OOP PART II
02 Java Language And OOP PART II02 Java Language And OOP PART II
02 Java Language And OOP PART II
 
control statements
control statementscontrol statements
control statements
 
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event SystemsFunctional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event Systems
 
Chapter 3:Programming with Java Operators and Strings
Chapter 3:Programming with Java Operators and  StringsChapter 3:Programming with Java Operators and  Strings
Chapter 3:Programming with Java Operators and Strings
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Chapter 3 : Programming with Java Operators and Strings
Chapter 3 : Programming with Java Operators and  StringsChapter 3 : Programming with Java Operators and  Strings
Chapter 3 : Programming with Java Operators and Strings
 
Java script
Java scriptJava script
Java script
 
chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Operator in JAVA
Operator in JAVA Operator in JAVA
Operator in JAVA
 

More from Jamsher bhanbhro

Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and InterfacesJamsher bhanbhro
 
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In  JavaMethod, Constructor, Method Overloading, Method Overriding, Inheritance In  Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In JavaJamsher bhanbhro
 
Regular Expressions in Java.
Regular Expressions in Java.Regular Expressions in Java.
Regular Expressions in Java.Jamsher bhanbhro
 
Java Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJava Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJamsher bhanbhro
 
Compiling and understanding first program in java
Compiling and understanding first program in javaCompiling and understanding first program in java
Compiling and understanding first program in javaJamsher bhanbhro
 
Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Jamsher bhanbhro
 

More from Jamsher bhanbhro (14)

Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
 
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In  JavaMethod, Constructor, Method Overloading, Method Overriding, Inheritance In  Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
 
Regular Expressions in Java.
Regular Expressions in Java.Regular Expressions in Java.
Regular Expressions in Java.
 
Java Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJava Arrays and DateTime Functions
Java Arrays and DateTime Functions
 
Lect10
Lect10Lect10
Lect10
 
Lect9
Lect9Lect9
Lect9
 
Lect8
Lect8Lect8
Lect8
 
Lect6
Lect6Lect6
Lect6
 
Lect5
Lect5Lect5
Lect5
 
Lect4
Lect4Lect4
Lect4
 
Compiling and understanding first program in java
Compiling and understanding first program in javaCompiling and understanding first program in java
Compiling and understanding first program in java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Caap presentation by me
Caap presentation by meCaap presentation by me
Caap presentation by me
 
Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)
 

Recently uploaded

TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 

Recently uploaded (20)

TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 

Lect7

  • 1. Basic Operators and Loop Control in Java. •Arithmetic Operators?. •Logical Operators?. •Relational Operators?. •Bit wise Operators?. •Assignment Operators?. •For, while, do whole loop in java? •Break and Continue Statements? 4/10/2019 1Jamsher Bhanbhro(F16CS11)
  • 2. Basic Operators • Arithmetic Operators: These are same which are used in mathematical expressions. • These are (+,-,*,/,%,++,--). • Relational Operators: These are used to relate expressions methomatically • These are (==, >=, <=, >, <, !=) used in java. • Bitwise Operator: Operations performed on bits • These are (&’bitwise AND’, II’or’, ^’XOR’, <<‘LEFTSHIFT’, >>’rightshift’, >>>’zeroshift’ ). 4/10/2019 Jamsher Bhanbhro(F16CS11) 2
  • 3. Basic Operators. • Logical Operators: These are used when there are two condition in a statement. • These are (&&, II, !). • Assignment Operators: These are operators which are used to assign the values. • These are(=,=+, -=, *=, /=, %=,<<=, >>=) 4/10/2019 Jamsher Bhanbhro(F16CS11) 3
  • 4. Write a program to demonstrate all basic operators in java. 4/10/2019 Jamsher Bhanbhro(F16CS11) 4
  • 5. Program Cont… • Guess the output of the above program. • Note: Write a program to use all the types of each basic operator. 4/10/2019 Jamsher Bhanbhro(F16CS11) 5
  • 6. Loops • Loops are used to execute a code of block for several times. • A loop Consists of a conditional code and a condition. • The code of block will run till the condition is true. There are three loops in java. If true else 4/10/2019 Jamsher Bhanbhro(F16CS11) 6 Condition Execute Code
  • 7. 1. While Loop • Continues or execute the code till the condition is true. • Tests condition before executing the code. • Syntax: while(condition){} • E.g: int a=4, b=11; while(b<12){ System.out.println(“output=”+(a+b)); } 4/10/2019 Jamsher Bhanbhro(F16CS11) 7
  • 8. While Syntax While(bool exp) if true else 4/10/2019 Jamsher Bhanbhro(F16CS11) 8 Condition Boolean Expression Execute Code
  • 9. 2. For Loop • Executes the code multiple times • Approximately same as while but there is some difference. • In this loop we will give initialization, condition and increment values. • for(init, cond, update){code body} e.g: int a=11; for(int i=0; i<=a; i++){ System.out.println(“Hello”); } 4/10/2019 Jamsher Bhanbhro(F16CS11) 9
  • 10. For Syntax While(bool exp) if true else incr 4/10/2019 Jamsher Bhanbhro(F16CS11) 10 Condition Boolean Expression Execute Code Update Cond
  • 11. 3. Do While Loop • Same as while loop but.. • Executes at least once without checking condition. • do{}while(cond) int a=1, b=3; do{ System.out.println(a*b); }while(a!=b) 4/10/2019 Jamsher Bhanbhro(F16CS11) 11
  • 12. 3. Do Syntax While(bool exp) if true else 4/10/2019 Jamsher Bhanbhro(F16CS11) 12 Condition Boolean Expression Execute Code
  • 13. Why Loops are used write the advantages. • Loops are used to reduce the code. • Loops provide flexibility to the code. • Loops are highly used in the programming specially when we are related with arrays. • Although it is very important to remember the syntax and the phenomenon of the loops structures. 4/10/2019 Jamsher Bhanbhro(F16CS11) 13
  • 14. Break and Continue Statements • When the break statement is encountered inside a loop. • It breaks the statement and gives the current flow to the next level. • Switch() in the cases this break is used. Eg: int a=11; if(a>10){ break; } 4/10/2019 Jamsher Bhanbhro(F16CS11) 14
  • 15. Continue Statement • Continue statement is used when we want to continue our block of code. • Used for jumping purpose. • In the for loop continue is used to jump to update statement. • In while continue used to jump to a Boolean expression. • Syntax: continue; int a=15; if(a>11){ continue; } 4/10/2019 Jamsher Bhanbhro(F16CS11) 15
  • 16. Tasks Write a program to draw shape of • Triangle • Rectangle • Pyramid • Diamond • Write a program to make a simple calculator of at least six functions using break and continue statement. 4/10/2019 Jamsher Bhanbhro(F16CS11) 16