SlideShare ist ein Scribd-Unternehmen logo
1 von 22
MATLAB
Looping
Control Statements
CS-5
By: Prof. Ganesh Ingle
Course Main Topic/Chapters
Introduction
Overview of Loop statement
For loop
While loop
Nested loop
While loop vs for loop
Introduction
A loop is used for executing a block of
statements repeatedly until a particular
condition is satisfied.
For example, when you are displaying number from
1 to 100 you may want set the value of a variable
to 1 and display it 100 times, increasing its value
by 1 on each loop iteration.
Introduction
A loop is used for executing a block of
statements repeatedly until a particular
condition is satisfied.
For example, when you are displaying number from
1 to 100 you may want set the value of a variable
to 1 and display it 100 times, increasing its value
by 1 on each loop iteration.
Basic Structure of a Loop Statement
A loop is used for
executing a block
of statements
repeatedly until a
particular
condition is
satisfied.
Types of Loops
Loops are of 2 types:
Entry-controlled and exit-controlled.
'C' programming provides us
1) while
2) for loop
3) Nested Loop
For and while loop are also called as entry-
controlled loops.
Questions to be Asked ??
In the exam questions can be asked are
1) What do you mean by loop control
statement explain in detail.
Answer: Must include: syntax, example,
flowchart, entry control and exit
control loop difference
2) Write a program ………..
for Loop Syntax
for Loop Example
for index = values, statements, end executes a group of statements in a
loop for a specified number of times. values has one of the following
forms:
initVal:endVal — Increment the index variable from initVal to endVal by
1, and repeat execution of statements until index is greater than
endVal.
initVal:step:endVal — Increment index by the value step on each
iteration, or decrements index when step is negative.
valArray — Create a column vector, index, from subsequent columns of
array valArray on each iteration. For example, on the first iteration,
index = valArray(:,1). The loop executes a maximum of n times, where
n is the number of columns of valArray, given by numel(valArray(1,:)).
The input valArray can be of any MATLAB data type, including a
character vector, cell array, or struct.
while Loop Syntax
while vs for Loop
Programming Exercise
Lets start with programming!!!
Programming Exercise
Q.1 WAP to display Fibonacci series up to n terms
Programming Exercise
Q.2 WAP to display Fibonacci series up to n terms (Different logic)
Programming Exercise
Q.3 WAP to Check entered number is magic number
(Condensing a number to single digit, if the yielded single digit is one(1) then it is termed as magic number)
Programming Exercise
Q.4 WAP to Check entered number is Palindrome number
Number= Reverse number
Programming Exercise
Q.5 WAP to Check entered number is perfect number
Programming Exercise
Q.6 WAP to Check entered number is prime number
Programming Exercise
Q.7 WAP to Check entered number is Special number,
Digits factorial addition = number , 145=1!+4!+5!=145
Programming Exercise
Q.8 WAP to Check entered number is Armstrong number,
Digits cube addition = number , 153
Programming Exercise
Q. 9 Display pattern
THANK YOU

Weitere ähnliche Inhalte

Was ist angesagt?

Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming LanguageMahantesh Devoor
 
While loop
While loopWhile loop
While loopFeras_83
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programmingCHANDAN KUMAR
 
Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Muhammad Tahir Bashir
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareGagan Deep
 
Looping statement
Looping statementLooping statement
Looping statementilakkiya
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 
Nested loop in C language
Nested loop in C languageNested loop in C language
Nested loop in C languageErumShammim
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
Control statements anil
Control statements anilControl statements anil
Control statements anilAnil Dutt
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Pythonprimeteacher32
 

Was ist angesagt? (20)

Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
While loop
While loopWhile loop
While loop
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Control statements
Control statementsControl statements
Control statements
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Forloop
ForloopForloop
Forloop
 
Looping statement
Looping statementLooping statement
Looping statement
 
While loops
While loopsWhile loops
While loops
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
The Loops
The LoopsThe Loops
The Loops
 
Nested loop in C language
Nested loop in C languageNested loop in C language
Nested loop in C language
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Loop c++
Loop c++Loop c++
Loop c++
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
Break and continue
Break and continueBreak and continue
Break and continue
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Python
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
 

Ähnlich wie Programming with matlab session 5 looping

Ähnlich wie Programming with matlab session 5 looping (20)

Loops_in_Rv1.2b
Loops_in_Rv1.2bLoops_in_Rv1.2b
Loops_in_Rv1.2b
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
L06
L06L06
L06
 
Programming loop
Programming loopProgramming loop
Programming loop
 
Ma3696 lecture 4
Ma3696 lecture 4Ma3696 lecture 4
Ma3696 lecture 4
 
Loops Do While Arduino Programming Robotics
Loops Do While Arduino Programming  RoboticsLoops Do While Arduino Programming  Robotics
Loops Do While Arduino Programming Robotics
 
Python_Module_2.pdf
Python_Module_2.pdfPython_Module_2.pdf
Python_Module_2.pdf
 
Loops c++
Loops c++Loops c++
Loops c++
 
Conditional Loops Python
Conditional Loops PythonConditional Loops Python
Conditional Loops Python
 
Loops in R
Loops in RLoops in R
Loops in R
 
Notes2
Notes2Notes2
Notes2
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
Repetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesRepetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniques
 
PYTHON.pptx
PYTHON.pptxPYTHON.pptx
PYTHON.pptx
 
Java best practices
Java best practicesJava best practices
Java best practices
 
Looping statements
Looping statementsLooping statements
Looping statements
 

Mehr von Infinity Tech Solutions

Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5Infinity Tech Solutions
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automationInfinity Tech Solutions
 
Computer memory, Types of programming languages
Computer memory, Types of programming languagesComputer memory, Types of programming languages
Computer memory, Types of programming languagesInfinity Tech Solutions
 
AI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime SectorAI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime SectorInfinity Tech Solutions
 

Mehr von Infinity Tech Solutions (20)

Database management system session 6
Database management system session 6Database management system session 6
Database management system session 6
 
Database management system session 5
Database management system session 5Database management system session 5
Database management system session 5
 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5
 
Database Management System-session1-2
Database Management System-session1-2Database Management System-session1-2
Database Management System-session1-2
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automation
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
E commerce
E commerce E commerce
E commerce
 
E commerce
E commerceE commerce
E commerce
 
Bds session 13 14
Bds session 13 14Bds session 13 14
Bds session 13 14
 
Computer memory, Types of programming languages
Computer memory, Types of programming languagesComputer memory, Types of programming languages
Computer memory, Types of programming languages
 
Basic hardware familiarization
Basic hardware familiarizationBasic hardware familiarization
Basic hardware familiarization
 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
 
Programming with matlab session 3 notes
Programming with matlab session 3 notesProgramming with matlab session 3 notes
Programming with matlab session 3 notes
 
AI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime SectorAI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime Sector
 
BIG DATA Session 7 8
BIG DATA Session 7 8BIG DATA Session 7 8
BIG DATA Session 7 8
 
BIG DATA Session 6
BIG DATA Session 6BIG DATA Session 6
BIG DATA Session 6
 
MS word
MS word MS word
MS word
 
DBMS CS 4-5
DBMS CS 4-5DBMS CS 4-5
DBMS CS 4-5
 
DBMS CS3
DBMS CS3DBMS CS3
DBMS CS3
 

Kürzlich hochgeladen

System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Crushers to screens in aggregate production
Crushers to screens in aggregate productionCrushers to screens in aggregate production
Crushers to screens in aggregate productionChinnuNinan
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentBharaniDharan195623
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solidnamansinghjarodiya
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...Erbil Polytechnic University
 
Crystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptxCrystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptxachiever3003
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 

Kürzlich hochgeladen (20)

System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Crushers to screens in aggregate production
Crushers to screens in aggregate productionCrushers to screens in aggregate production
Crushers to screens in aggregate production
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managament
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solid
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Crystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptxCrystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptx
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 

Programming with matlab session 5 looping

  • 2. Course Main Topic/Chapters Introduction Overview of Loop statement For loop While loop Nested loop While loop vs for loop
  • 3. Introduction A loop is used for executing a block of statements repeatedly until a particular condition is satisfied. For example, when you are displaying number from 1 to 100 you may want set the value of a variable to 1 and display it 100 times, increasing its value by 1 on each loop iteration.
  • 4. Introduction A loop is used for executing a block of statements repeatedly until a particular condition is satisfied. For example, when you are displaying number from 1 to 100 you may want set the value of a variable to 1 and display it 100 times, increasing its value by 1 on each loop iteration.
  • 5. Basic Structure of a Loop Statement A loop is used for executing a block of statements repeatedly until a particular condition is satisfied.
  • 6. Types of Loops Loops are of 2 types: Entry-controlled and exit-controlled. 'C' programming provides us 1) while 2) for loop 3) Nested Loop For and while loop are also called as entry- controlled loops.
  • 7. Questions to be Asked ?? In the exam questions can be asked are 1) What do you mean by loop control statement explain in detail. Answer: Must include: syntax, example, flowchart, entry control and exit control loop difference 2) Write a program ………..
  • 9. for Loop Example for index = values, statements, end executes a group of statements in a loop for a specified number of times. values has one of the following forms: initVal:endVal — Increment the index variable from initVal to endVal by 1, and repeat execution of statements until index is greater than endVal. initVal:step:endVal — Increment index by the value step on each iteration, or decrements index when step is negative. valArray — Create a column vector, index, from subsequent columns of array valArray on each iteration. For example, on the first iteration, index = valArray(:,1). The loop executes a maximum of n times, where n is the number of columns of valArray, given by numel(valArray(1,:)). The input valArray can be of any MATLAB data type, including a character vector, cell array, or struct.
  • 11. while vs for Loop
  • 12. Programming Exercise Lets start with programming!!!
  • 13. Programming Exercise Q.1 WAP to display Fibonacci series up to n terms
  • 14. Programming Exercise Q.2 WAP to display Fibonacci series up to n terms (Different logic)
  • 15. Programming Exercise Q.3 WAP to Check entered number is magic number (Condensing a number to single digit, if the yielded single digit is one(1) then it is termed as magic number)
  • 16. Programming Exercise Q.4 WAP to Check entered number is Palindrome number Number= Reverse number
  • 17. Programming Exercise Q.5 WAP to Check entered number is perfect number
  • 18. Programming Exercise Q.6 WAP to Check entered number is prime number
  • 19. Programming Exercise Q.7 WAP to Check entered number is Special number, Digits factorial addition = number , 145=1!+4!+5!=145
  • 20. Programming Exercise Q.8 WAP to Check entered number is Armstrong number, Digits cube addition = number , 153
  • 21. Programming Exercise Q. 9 Display pattern