For Statement (Contd.)

Problem solving through Programming In C - IITKGP
8 Feb 201827:26

Summary

TLDRThis script discusses the use of the for loop in programming, exploring its structure including initialization, condition checking, and modulator expressions. It highlights the ability to use arithmetic expressions within the loop and the potential for infinite loops. Examples are provided to illustrate how to compute factorials and sum of squares using for loops. The script also touches on the use of the break and continue statements to control loop execution, emphasizing best practices for readability and logic in programming.

Takeaways

  • 🔁 The for loop is a control structure used for creating loops in a program, consisting of initialization, condition checking, and a modulator (alteration) expression.
  • 📐 Arithmetic expressions are used within the for loop for initialization and condition checking, allowing for complex conditions and variable manipulation.
  • 🔄 The modulator expression can be used to increment or decrement the loop control variable, or to modify it in other ways, hence it's sometimes better referred to as an alteration expression.
  • ⏪ The for loop can be used to create loops that count down, not just up, by using a decrementing modulator expression.
  • 🚫 If the loop continuation condition is false from the start, the body of the for loop will not be executed even once.
  • 🎲 Examples provided in the script demonstrate how to compute factorials and sum of squares using for loops, showcasing their versatility.
  • 🔀 The comma operator allows for multiple initialization or alteration expressions within the for loop, although it's advised against for beginners due to potential readability issues.
  • 🔁 Infinite loops can be created using for loops by omitting the initialization, condition, and modulator expressions, resulting in a loop that runs indefinitely.
  • 🛑 The break statement can be used to exit a for loop prematurely when a specific condition is met, allowing for early termination of the loop.
  • 🔁 The continue statement is used to skip the remaining part of the loop body and proceed to the next iteration of the loop.

Q & A

  • What is the purpose of the 'for' statement in programming?

    -The 'for' statement is used to create loops in a program, allowing for repeated execution of a block of code as long as a specified condition is true.

  • What are the three main components of a 'for' loop?

    -The three main components of a 'for' loop are the initialization expression, the loop continuation condition, and the alteration expression.

  • Can the increment in a 'for' loop be negative?

    -Yes, the increment in a 'for' loop can be negative, allowing the loop to count down or decrement the loop control variable.

  • What is an infinite loop and how can it be created using a 'for' loop?

    -An infinite loop is a loop that continues to execute indefinitely because the loop continuation condition never becomes false. It can be created using a 'for' loop by omitting the initialization, condition, and alteration parts, or by setting the condition to always be true.

  • What is the role of the 'break' statement in loops?

    -The 'break' statement is used to exit a loop prematurely when a certain condition is met, preventing further iterations of the loop.

  • How does the 'continue' statement function within a loop?

    -The 'continue' statement is used to skip the remaining part of the loop body and proceed to the next iteration of the loop.

  • What is the significance of the comma operator in the context of 'for' loops?

    -The comma operator allows multiple expressions to be included in the initialization or alteration part of a 'for' loop, separating them with commas.

  • Why might a programmer choose to use a 'do while' loop instead of a 'for' loop?

    -A programmer might choose to use a 'do while' loop instead of a 'for' loop when they want to ensure that the loop body executes at least once before the condition is checked.

  • Can you provide an example of how a 'for' loop can be used to compute the factorial of a number?

    -A 'for' loop can be used to compute the factorial of a number by initializing a variable to 1, using a loop to multiply this variable by each integer up to the number, and breaking the loop when the factorial exceeds a certain value.

  • What is the difference between a 'for' loop and a 'while' loop in terms of their syntax and usage?

    -A 'for' loop is more compact and is typically used when the number of iterations is known beforehand, while a 'while' loop is used when the number of iterations is not known and depends on a condition that is checked before each iteration.

Outlines

00:00

🔁 Understanding For Loops

This paragraph delves into the intricacies of for loops in programming, emphasizing their structure and functionality. It begins by contrasting for loops with while and do-while loops previously discussed. The for loop is dissected into three components: initialization, condition checking, and a modulator (previously termed 'increment'). The paragraph clarifies that the modulator can be any arithmetic expression, not just an increment, and illustrates this with examples. It also introduces the concept of a negative increment, or decrement, to reverse the order of operations within the loop. The paragraph concludes with a cautionary note on the complexity of expressions within for loops, advising beginners to prioritize clarity over brevity.

05:01

📉 Looping in Reverse with For Loops

The second paragraph demonstrates the use of for loops to iterate in reverse order. It provides a practical example where the loop prints numbers from 10 down to 5. This is achieved by initializing a variable 'j' to 10 and decrementing it within the loop until it reaches 5. The discussion highlights the flexibility of the for loop's structure, where the modulator part can be adjusted to not only increment but also decrement the loop variable. The paragraph also touches on the importance of the loop continuation condition, explaining that if this condition is false from the start, the loop body will not execute. It concludes with an example of computing factorials using a for loop, emphasizing the loop's utility in repetitive tasks.

10:04

🔢 For Loops for Summation and Factorials

This paragraph explores the application of for loops in summing series and calculating factorials. It presents a for loop that calculates the sum of squares of the first N natural numbers, explaining how the loop accumulates the sum with each iteration. Additionally, it revisits the factorial calculation, introducing the comma operator to condense the initialization and incrementation steps into a single line. The paragraph also addresses common pitfalls for beginners, such as omitting variable declarations and the potential for overly compact code to reduce readability. It concludes with a reminder to prioritize logical and syntactical correctness over code brevity.

15:10

🔄 Infinite Loops and Control Statements

The fourth paragraph introduces the concept of infinite loops, explaining how they occur when a loop's continuation condition never becomes false. It provides examples of how infinite loops can be intentionally created using for and while constructs, such as using 'for (;;)' or 'while (1)'. The paragraph also discusses the utility of infinite loops for tasks that require continuous operation. It then transitions into the discussion of control statements like 'break' and 'continue', explaining their role in exiting loops prematurely or skipping parts of the loop body. The 'break' statement is illustrated with an example where it is used to terminate a loop once a factorial exceeds a certain value, showcasing its use in conditional loop termination.

20:20

🚫 Breaking and Continuing Loops

This paragraph delves deeper into the use of 'break' and 'continue' statements within loops. It explains that 'break' is used to exit a loop immediately when a specific condition is met, using a factorial calculation example to demonstrate its application. The 'continue' statement, on the other hand, is shown to skip the remaining part of the loop body and proceed to the next iteration. The paragraph provides a detailed walkthrough of how these statements affect loop execution, emphasizing their utility in controlling loop flow. It concludes with a reminder of the importance of understanding loop mechanics for effective programming.

Mindmap

Keywords

💡for statement

The 'for' statement is a control flow language construct that allows code to be executed repeatedly based on a given Boolean condition. In the context of the video, the 'for' statement is used to create loops in a program, which are essential for executing a block of code multiple times. The script explains that a 'for' loop consists of three main components: initialization, condition checking, and a modulator (which can be an increment or decrement). An example given is 'for (j = 5; j <= 25; j += 5)', which initializes 'j' to 5, checks if 'j' is less than or equal to 25, and then increments 'j' by 5 each iteration.

💡arithmetic expression

An 'arithmetic expression' refers to a combination of numbers, mathematical operators, and variables that together evaluate to a single value. In the video, arithmetic expressions are used within the 'for' loop to define the initialization and modulator parts. For instance, the script mentions expressions like 'x = 2' and 'y = 10', and how they can be used to set up conditions within the loop, such as 'j <= 4 * x * y', which would be true if 'j' is less than or equal to 80 given 'x' and 'y' values.

💡increment

The term 'increment' in programming refers to the operation of increasing a variable's value by a certain fixed amount, typically by one. However, the video script suggests using the term 'modulator' instead, as the alteration can also be a decrement or any other form of change. For example, in a 'for' loop, 'j++' is an increment operation that increases 'j' by one after each loop iteration.

💡decrement

Similar to 'increment', 'decrement' is the operation of reducing a variable's value by a certain amount, usually one. The script uses 'decrement' in the context of creating a loop that counts down, such as 'j--' in a 'for' loop that starts at 10 and decrements 'j' until it is less than 5, allowing for reverse order printing of numbers.

💡modulator

A 'modulator' in the context of loops refers to the part of the loop structure that alters the loop control variable. The script suggests this term over 'increment' or 'decrement' because it can represent any form of alteration, including multiplication or division. For example, 'j += y / x' in a loop could modulate 'j' by adding the result of 'y' divided by 'x' to 'j' each iteration.

💡initialization

Initialization in the context of loops is the process of setting the initial value of the loop control variable. The script explains that in a 'for' loop, the initialization is done before the loop starts, such as 'j = 5', which sets the starting point for the loop variable 'j'.

💡loop continuation condition

The 'loop continuation condition' is the Boolean expression that must evaluate to true for the loop to continue executing. If the condition is false, the loop terminates. The script provides an example where if 'j' is initially set to 20 and the condition is 'i > j', the loop body will not execute because the condition is false from the start.

💡factorial

A 'factorial' of a non-negative integer 'n' is the product of all positive integers less than or equal to 'n'. It is denoted by 'n!'. In the script, an example of computing a factorial using a 'for' loop is given, where the loop multiplies the current 'fact' variable by the loop index 'i', incrementing 'i' each time until a certain condition is met.

💡infinite loop

An 'infinite loop' is a loop that will continue to execute until an external factor interrupts it, because its continuation condition never evaluates to false. The script warns about the possibility of infinite loops and provides an example of how a loop with a condition that never changes (like 'i++' inside the loop and 'i--' outside the condition check) will result in an infinite loop.

💡break statement

The 'break' statement is used to immediately exit a loop or switch statement. In the script, it is explained as a way to terminate a loop before the loop's condition becomes false, which can be useful for exiting a loop when a certain condition is met, such as when a factorial exceeds a certain value.

💡continue statement

The 'continue' statement is used to skip the remaining part of the loop body and proceed to the next iteration of the loop. The script provides an example where 'continue' is used in a loop that calculates factorials, skipping the rest of the loop body if 'i' is less than 10 and forcing the loop to start the next iteration immediately.

Highlights

Introduction to the creation of loops using the for statement in programming.

Explanation of the for statement structure with initialization, condition checking, and alteration expressions.

Use of arithmetic expressions within the for loop structure.

Example of a for loop with a positive incrementing modulator.

Demonstration of a for loop with a negative decrementing modulator for reverse order printing.

Clarification that the alteration expression in a for loop can be any arithmetic operation, not just increment or decrement.

Discussion on the importance of the loop continuation condition and its impact on loop execution.

Example of a factorial calculation using a for loop.

Illustration of computing the sum of squares of natural numbers up to N using a for loop.

Introduction to the comma operator for including multiple initialization or alteration statements in a for loop.

Caution against using the comma operator for初学者 to avoid confusion and maintain code readability.

Definition and example of an infinite loop and its practical applications.

Explanation of how to create an infinite loop using a for statement with empty initialization, condition, and alteration parts.

Introduction to the break statement for exiting a loop prematurely based on a specific condition.

Example of using break in a while loop to exit when a factorial exceeds a certain value.

Introduction to the continue statement for skipping the remaining part of a loop's body and proceeding to the next iteration.

Example illustrating the combined use of continue and break statements in a loop.

Emphasis on understanding the for loop for repetition as a fundamental concept in programming.

Transcripts

play00:10

Now, we are discussing about formation of loops,  

play00:19

creation of loops in a program using for  statement. Before that we have seen the  

play00:26

while statement and do while statement and  then we have seen the for statement as well.

play00:32

Now, the for statement as we had shown  we had discussed in the last class it is  

play00:39

basically starting to take an expression,  arithmetic expression and then it starts  

play00:48

with in sorry initialization expression and  then we check a particular condition. So,  

play00:57

something like this for some variable integer  variable j assigned some value 5 maybe and then  

play01:14

some expression here this one is j less than equal  to 25 and then here there will be some statements  

play01:28

which will be executed and after that there is a  third expression which is altering it and that can  

play01:36

be j assigned j plus 5 all right and the body of  the x loop. These are structure that we had seen.

play01:48

Now, there are some critical issues that  are to be noted for the for structure.

play01:57

So, if you look at this you can see that we  are using arithmetic expressions. For example,  

play02:08

x assigned 2 and y assigned 10 that is an  arithmetic expression. So, similarly this  

play02:16

is a valid arithmetic expression for j assigned x,  j less than equal to 4 times x times y that is the  

play02:27

condition. That means, after some computation  will have to find out whether j is satisfying  

play02:36

this condition and here j here probably this is  something this construct we have not shown you,  

play02:47

this is I do not like it very much and initially  you need not bother about this j plus equal to y  

play02:58

by x this is a C structure, say C syntax  expressing j equals j plus y by x. So,  

play03:13

the whole thing can be written in this way. So, this, but that is not important for the  

play03:20

purpose of understanding for expressions.  So, here is just an expression.

play03:26

And this is equivalent to like this for say x  was 2 and y was 10, then this is equivalent to  

play03:40

j assigned 2 because j assigned x and j assigned  2 are essentially same; j as less than equal to 4  

play03:48

times x times y that means, 4 times 2 times 10  that means, 80 and j equals assigned j plus y  

play04:01

by x is 5. So, this is equivalent all right. So,  this is initialization, this is loop continuation  

play04:11

condition and this is the increment or I as I was  saying that this is a modulator or the alteration. 

play04:19

Now, increment can be negative. So, this increment  all the way we are calling it increment that is  

play04:25

why we should not call it increment let us call  it a modulator because say the same thing I can  

play04:32

write as for j assigned 2 maybe something j less  than equal to 80 and might be j minus minus. It  

play04:47

can be the case when can it be. Say for example,  if I add if I want that I will be printing the  

play05:00

numbers in the reverse order starting from 10.  So, what should I do? So, can I do this what I  

play05:11

want to do is, that I want to print something  like 10 9 8 7 5 all right in this order.

play05:21

So, simply I can do this repeatedly in a loop  for example, for j assigned 10 and j sorry, j  

play05:50

greater than equal to 5 j minus minus and here  I just do printf percentage d backslash n j. So,  

play06:20

what will happen? Initially j is 10 less greater  than equal to 5, so 10 will be printed. Then I  

play06:29

go back I decrement j. So, j will become 9 still  greater than equal to 5 I come in here print j 9,  

play06:40

I again decrement j decrement j becomes 8 I  compare with this still it is greater than  

play06:48

equal to 5 I get in and printed. In that way I  can do it I can repeatedly do the same thing,  

play06:56

but here as you can see I am being able to  achieve this reverse order by instead of  

play07:03

incrementing and decrementing this index.  That is why I can increment to decrement,  

play07:09

I can multiply it, I change it, I modulate  it, that is why this to an alteration  

play07:16

expression or modulation expression is a  better term than increment or decrement.

play07:23

So, if the loop continuation, if  the loop continuation condition is  

play07:37

initially false is initially false then  the body struck the for structure will  

play07:45

not be executed. It will proceed with  the statement for the next statement.

play07:51

So, for example, if I write something  like this as you have seen earlier j  

play07:59

equal to 20 and for i equals i assigned 1,  i greater than j i plus plus say and then I  

play08:19

want to do some things here all right. Now, j is 20 I will first initialize i  

play08:26

to 1 and immediately I find the first thing  that I do is its false I check this and its  

play08:33

false i is not greater than j therefore,  this stay these statements will not be  

play08:39

executed even once and the statements  following the for loop will be executed.

play08:51

Now, here are some examples of for loops.  This is again computing the factorial  

play09:05

fact. Factorial is a the variable, fact is  touring the factorial factorial all of you  

play09:15

know as factorial n is n multiplied by n minus 1  multiplied by n minus 2 so on so forth up to 1. 

play09:23

So, it is 1 and I have got a variable i. Now, you  can see simply I can do it like this i assigned 1,  

play09:33

i less than 10 i plus plus fact assign fact  times i. Now, what is happening here? So,  

play09:41

I have got fact to be 1. So, i equals 1  then with that what I do is 1 times 1 is  

play09:53

fine and I then make i to be 2 and then i, i  becomes then 2. So, 1 times 2 then i becomes  

play10:04

3 then 1 times 2 times 3 then i becomes 4  then 1 times 2 times 4 times 3 times 4 and  

play10:14

so on and so forth it will go on in this loop.  So, that is a nice way of writing factorial.

play10:22

And here is another example you can see what it  does quickly. You can explain it yourself what  

play10:33

it does. Sum is 0 and N is a variable and count  is another integer variable all right. Sum is 0,  

play10:44

N is a 1 variable and count is  another integer variable. Now,  

play10:49

we are reading N and for i equals 1, i less  than equal to N I am adding some. So, what is  

play11:00

being done here what will happen if I press this  program what is going to happen? Let us do that. 

play11:06

Suppose I have read N to be here, I have read N to  be 5. Now, what am I doing here? I here there is  

play11:19

one problem here i should have been declared there  is a mistake here int N and here i also add i  

play11:27

should have been declared here. Now, i assigned 1.  So, i is 1, N was 5, i less than 5 less than equal  

play11:41

to 5. So, sum is sum was 0. So, sum is 0 plus i  times i, i was 1. So, 0 plus 1 square and then I  

play11:58

check i increment i. So, i becomes 2, i becomes  2 and I check that i is less than it not less  

play12:10

than a is still less than equal to 5 so I got this  sum and with that I add now, i square i times i,  

play12:19

so 2 square. Similarly, it will go on it will do  3 square. So, i will become then 4 and then still  

play12:30

it is less than equal to, so 4 square then  i will become 5 and still it is true. So, it  

play12:41

will be 5 squared then i become 6 this condition  will be violated and i will come to this printf. 

play12:47

So, what will sum be sum is 1 square plus 2  square plus 3 square and if I make it N then  

play12:58

up to N square. So, this is the very well known  series the sum of the square of natural numbers  

play13:06

we can compute by this small program using  for loop right. So, it is a nice example.

play13:17

Now, we introduce the comma operator. As we say  that here for when we write for then i assigned  

play13:35

1 instead of that I can put in more than one  statements here using a comma operator. For  

play13:44

example, for fact 1 i equals 1, i less than  equal to 10. Now, this part is what? This part  

play13:55

is the initialization. Now, remember that  this will not be continuously initialized,  

play14:07

this is just an just a statement that  I put here an assignment statement,  

play14:14

but my index variable for the control variable  for the loop is i. So, I could have written  

play14:20

this earlier example of factorial maybe,  earlier example of factorial this could be  

play14:28

initialized here also all right. So, that is just  saving space saving the number of lines of code. 

play14:34

But personally I would suggest as I did earlier  also that is for of those of you who are beginners  

play14:42

in programming you should not try this tricks  or should not try this thriftiness reducing  

play14:50

the number of lines, that is not so important  to how much you can reduce. The most important  

play14:55

thing is to be logically can syntactically  correct while you write a program ok. 

play15:01

So, we can give several things in comma like some  here again. So, the program becomes even smaller  

play15:09

look smarter, but sometimes at the beginning  if you try to do that you try to be smart and  

play15:16

in the process you may result in some long  program long long logic better avoid that.

play15:26

Now, infinite loop in general what is an  infinite loop. When a program continues,  

play15:36

program continues in a loop repeatedly it goes on  and it is never completing its going on because  

play15:48

the condition that is supposed to turn out to  be false at a particular point of time. So,  

play15:58

that it comes up the out of the loop never  happens all right. That can always happen  

play16:04

that say if I write something like for i equals  1, i less than n and whatever i plus plus. Now,  

play16:20

every time inside the loop when you get in you  read you do something and then increment i and  

play16:31

when you come inside the loop you do i minus  minus, then whatever has been done here will be  

play16:38

canceled out here. So, this loop will never reach  this condition I less than i therefore, that this  

play16:50

loop will continue forever such situations  are known as the condition of infinite loop. 

play16:57

Now, sometimes usually we do not like that,  but sometimes it may be necessary to specify  

play17:05

that something will happen forever all right. Say  some particular work has to be done continuously.

play17:13

Now, in order to specify that for loop  provides us some facility like say for  

play17:25

and while everything say this one we had  discussed earlier while 1, that means,  

play17:31

always it is true it is a nonzero this  while loop this expression part condition  

play17:37

expression part should return nonzero and so  it will go on. Now, here for and I put null;  

play17:48

that means, the for has had 3 parts, for the  initialization part, some condition part and some  

play18:04

incrementation decrementation part whatever. Now, I just keep everything blank. So,  

play18:11

I turn it to be for nothing and nothing all  these things are blank. In that case what  

play18:21

will happen? In that case what will happen? If I  keep some statements here that will go on forever.  

play18:32

Similarly if I in the case of do while if I just  put while 1 that is again in finite loop. So,  

play18:41

by this I can express my desire that some things  will have should continue forever all right. So,  

play18:52

this is another trick that you can utilize in  some cases for the for and the while constraints.

play19:04

Now, we come to another statement which we have  encountered a little few lectures earlier in  

play19:13

the context of switch statements. While we are  considering the switch statements if you recall  

play19:20

you have seen that after every case statement  switch on a particular variable then their case  

play19:26

red case, green case, blue if you recall then we  did something and then give a break, did something  

play19:35

give a break like that we proceeded right. So, the break statement of course, we know  

play19:42

can help us we can use it with several things  one is while, do while, for and switch. Now,  

play19:54

this switch, switch part we have seen, but we  can also use it for while do while and for,  

play20:04

for breaking out of the loop, we want to break  out of the loop. Sometimes that is required it  

play20:20

works with while, do while, for, but does not  work with if and else statement. It causes  

play20:31

immediately exit from a while for a do while or  case we have seen that switch statements earlier. 

play20:38

So, the program continues after with the  next statement let us see. Why do we want  

play20:51

to use it? It helps us to escape early from  a loop. Sometimes we want to escape early I  

play20:58

do not want to go till the end of the loop,  when a particular condition is met I want  

play21:03

to come out. I am doing it in a loop,  but waiting for some condition to take  

play21:07

place as soon as that condition takes  place I come out of the loop. Maybe,  

play21:14

as we have seen in the case statement switch  some expression all right color, then case R  

play21:27

we do something and then give break right, case  G we do something and then give break right we do  

play21:41

like that. So, we skip the remaining part of  the switch block right. We come out of that.

play21:49

So, similarly we will see a couple of examples of  this. Say here there is a complete example let us  

play21:58

look at that. Here is a complete example complete  program, once again include stdio dot h you are  

play22:06

running some programs main, then fact and i are  integers fact we are computing factorial. So,  

play22:15

fact is 1, i is 1, while i is less than  10; that means, I want to break out while  

play22:27

i is less than 10 fact times i, if fact is  greater than 100, then factorial is above  

play22:39

100 factorial of a number is above 100. So, for  example, I am going on up to 10 numbers. So,  

play22:48

what will happen with the factorials? Let us see.  So, factorial 1 will be 1, factorial 2 will be 2,  

play22:58

factorial 3 will be 3 times 2 that is 6, factorial  4 will be 4 times 3 for 4 times 6, it will be 4  

play23:12

times 3 times 2, so 4 times 6; that means 24, then  24 times 5, so that will be how much it will be,  

play23:30

more than how much will it be if I have got  this 4 3 2 and multiply that with 5, so 26. 

play23:41

So, here just with 5 numbers I am exceeding  the value 120, but I do not know when I am  

play23:52

going to reach the value 100. So, I  have written the program in this way,  

play23:57

fact while i is less than 10 I will test it up to  10 numbers every time, I compute fact if fact is  

play24:08

greater than 100 print. So, here as soon as fact  becomes 100 will say factorial of 5 is above 100,  

play24:20

factorial of 5 is above 100 and then I break out.  Otherwise if I had not put this break then this  

play24:31

would have continued till this loop all for all  the 10 numbers up to factorial 10, but I just want  

play24:40

to stop whenever my result becomes more than 100.  So, this is one way we can utilize a break right. 

play24:47

Similarly there is another statement although  we do not use it often it is better to know  

play24:53

that sometimes it can come handy, that  is a continued statement; that means,  

play24:57

the remaining part of the body of a loop  we will skip if I put a continue all right.

play25:03

So, let us see and it proceeds to  the next iteration of the loop. So,  

play25:07

what happens is let us look at one example here.

play25:11

So, while one that means what; that means,  it is always true. It will continually go  

play25:21

on doing it. So, fact is fact times i, i  plus plus. So, I start with i 1, then 2,  

play25:29

then 3. If i is less than 10 I will go  into the loop otherwise I will break. So,  

play25:38

this continue is basically remain  forcing me to go back to this point,  

play25:45

by forsaking this part. I am not coming to the  remaining of the loop, but if this condition is  

play25:55

not holding then I will not execute continue  I straight away come here and do break. I  

play26:01

think it will need a couple of moment for you to  just realize what is happening here all right. 

play26:09

So, just look at this. So, in this way it will I  think you can understand it. So, I have got i to  

play26:22

be 1. So, fact will be 1 times 1, then i becomes  2 and then I go back. So, it will be fact will be  

play26:40

1 times 1 times 2, i will be 3 and in that will  go on, but as it will go on as long as i is 10,  

play26:49

less than 10. Then i will not come to break I will  go back here. But if i is less than 10 i will come  

play26:56

to break and i will come out of the loop. So, it  is a combination of continue and break this is.  

play27:05

But what I want is that you should understand  how the for loop is used for repetition that is  

play27:13

very important to understand and will carry  out with some examples in the next lecture.

Rate This

5.0 / 5 (0 votes)

Etiquetas Relacionadas
For LoopsProgrammingCode StructureLoop ControlArithmetic ExpressionsModulation ExpressionsInfinite LoopsBreak StatementContinue StatementFactorial CalculationSum of Squares
¿Necesitas un resumen en inglés?