4.2 Loop Structure
If we need to repeat one or more statements, then we use loops. For example, if we need to write Pakistan thousand times on the screen, then instead of writing printf("Pakistan”); a thousand times, we use loops. C language provides three kind of loop structures:
1- Forloop
2- While loop
3- Do while loop
In this chapter, our focus is on for loops.
4.2.1 General structure of loops
If we closely observe the process that humans follow for repeating a task for specific number of times then it becomes easier for us to understand the loop structures that C language provides us for controlling the repetitions. Let’s assume that our sports instructor asks us to take 10 rounds of the running track. How do we perform this task? First we set a counter to zero, because we have not yet taken a single round off-the-rack. Then we start taking the rounds. After each round we increase our counter by 1and check whether we have completed 10 rounds or not yet. If we have not yet completed the 10 rounds then we again take a round, increase our counter by 1, and again check whether we have taken 10 rounds or not. We repeat this process till our counter reaches 10.Different programming languages follow similar philosophy in the loop structures for repeating a set of instructions.
4.2.2 General syntax of for loop
In C programming language, for loop has the following general syntax.
for initialization; condition; increment/decrement)
{
Code to repeat
}
From the flow chart, we can observe the following sequence:
1- Initialization is the first part to be executed in a for loop. Here we initialize our counter variable and then move to the condition part.
2- Condition is checked, and if it turns out to be false, then we come out ofloop.3- If the condition is true, then body of the loop is executed.
4- After executing the body of loop, the counter variable is increased or decreased depending on the used logic, and then we again move to the step 2.After executing the body of loop, the counter variable is increased or decreased depending on the used logic, and then we again move to the step 2.
Example Code 4.4
Timestamp
00:00 Intro
01:02 Loop Structure
02:28 Types of Loop Structure
03:05 General Structure of Loops
05:50 General Syntax of for Loops
06:50 Flowchart of “for loop Structure”
08:42 Example Code 4.4
12:13 Important Tip
12:36 Dou you know?
07:17 Outro
Social Media Links:
_____/❤ All Students are requested to Follow Me on Social Media!! ❤\_______
Instagram:➜ / digitaleduc. .
Twitter:➜ / shahbaz_ali101
Facebook Page:➜ / digitaleduca. .
Whatsapp:➜ https://chat.whatsapp.com/GqLGyGuZyNp...
Youtube:➜ https://bit.ly/32hA7C4?sub_confirmati...
10th Class Computer Science:
How to install and Download Code::Blocks:
https://bit.ly/3HuCBzO
10th Computer Science All Lectures Playlist:
https://bit.ly/3eYGMbb
10th Computer Science All Exercise Playlist:
https://bit.ly/3pMcoqu
10th Computer Science All Example Code Playlist:
https://bit.ly/3pKxxkK
10th Computer Science All Programming Time:
https://bit.ly/3eOmTmJ
10th Computer Science All Activities Playlist:
https://bit.ly/3eFQOh1
10th Computer Science All Programming Exercise Playlist:
https://bit.ly/3zltiQ6
9th Class Computer Science:
9th Computer Science Chapter 1:
https://bit.ly/3SCa6pR
9th Computer Science Chapter 2:
https://bit.ly/3SBi2I4
9th Computer Science Chapter 4:
https://bit.ly/3EfbEBT
9th Computer Science Chapter 4:
https://bit.ly/3EjLduP
9th Computer Science Chapter 5:
https://bit.ly/3SU0O8x
9th Computer Science All Exercise:
https://bit.ly/3EgNnvh
9th Computer Science All Activates:
https://bit.ly/3rrYppN
9th Computer Science Complete Lectures:
https://bit.ly/3t2BBhr
#loopinc
#forloopinc
#whatisloop
#typesofloopsinc
#definitionofforloop
#whatisloopinc
#whatisforloop
#typesofloopsincinhindi
#loop
#cprogrammingloopingstatement
#WhatisforloopinCprogramming?
#Whatisforloopanditssyntax?
#CforLoopHindi
#ForLoopinCHINDI
#ForloopinCwithexampleprogram
#forlooplecture
#lecureonforloop
#loopingusingforloopusingforloop
#whatisforloophindi
#whatisforloopinc
#DigitalEducation
#digitaleducationshahbazali #10thComputerChapter1
#10thComputerChapter2
#10thComputerChapter3
#10thComputerChapter4
#10thComputerChapter5
#10thComputer
#10thComputerChapter1Exercise
#10thComputerChapter2Exercise
#10thComputerChapter3Exercise
#10thComputerChapter4Exercise
#10thComputerChapter5Exercise
#10thComputerScience
#10thComputerPaper2022
#10thComputerPairingScheme2023
#10thComputerPaper2023
#10thComputerPairingScheme2023
#CLanguageTutorialforBeginners
#CLanguage
#CLanguageFullCourse
#CLanguageProgramming
#CLanguageCodewithHarry
#CLanguageFullCourseinHindi
#CLanguageBasics
#CLanguageTutorial
Computer Science 10th class
Lecturer of Computer Science
By Sir Shahbaz Ali
For any query or private tutoring contact (0309-0334424)
[email protected]