 The previous segment we discussed how we could modify the arrangement of code in our program or in our flow chart so that it matches the structure of the while loop so that we can use the while loop in our program. Next we will discuss a different way of doing the same thing but without too much rearrangement of any code. For this we need the so-called break statement. The break statement is perhaps the simplest statement, the word break is a keyword which by itself is a statement okay so you will see that an example so on. What happens when control reaches a break statement well the break statement had better be inside a while and if you reach the break statement the execution of the while statement which contains it is terminated. So the control then goes to the statement following the containing while statement that is about it. So here is an example of a break okay so main program float next mark sum as before count is 0 and now we are going to run the loop but we are going to run it with a condition true okay so I will explain this in a minute so we are going to read in the mark and if the next mark is less than 0 then we are going to break okay so the consequent over here is the single word statement break otherwise we are going to add next mark to sum we are going to increment count okay and that is it as far as the loop is concerned and then we are going to print. So I will claim that this program actually does what we want okay so why is that so first of all let us go to the new part the first new part is the while which contains true. So the condition of the while statement is given as true which means that this condition will always evaluate to true so which means whenever you try and check the condition it will come out to be true and you will always enter the body. So you will always enter the body so you will always read in the next mark. The next statement is if next mark less than 0 okay so if next mark less than 0 then there is the break statement and which means that the loop will terminate okay the execution of the while statement will terminate and you will execute you will come to this point and execute the statement okay. So remember that that was exactly what you wanted if next mark was less than 0 okay next mark was signaling the condition that no more input will be given and therefore you want the average to be calculated and printed otherwise you want the currently read mark to be treated as a real mark and you wanted added to sum so that is what is going to happen over here and you also want count to be incremented. So the nice part over here is that we did not need to copy this code remember in the earlier case we had to pull it out over here we had to move it to the end here we do not need to do anything like that and this pretty much resembles the way we think about this logic so when we wrote down when we thought about it manually we would say okay read the next mark if it is less than 0 then go off and terminate otherwise keep otherwise added to the sum and so on so this is exactly the way we think about it however some programmers do not like break statements because the condition continuation condition okay so this condition this is really the condition which tells whether or not you want to continue the loop or break the loop this continuation condition now is hidden inside the body whereas earlier it was at a nice obvious place okay so therefore some programmers have preference for not having a break statement but using a proper continuation condition over here and at the cost of maybe moving some code outside and moving at end of the loop body. So I think programmers do both of these things so you should pick the style that you are most comfortable with and then I should note that the condition for breaking okay is next mark less than 0 whereas the condition for continuing however is next mark greater than 0 so while next mark is greater than or equal to 0 I should execute this okay so they are of course complementary conditions but clearly one is the condition for continuing and other is the condition for breaking out so we should expect them to be exactly the opposite of each other so there is another single word statement that I should tell you about and this is the continue statement okay so if it is encountered in any execution then the control directly goes to the beginning of the loop for the next iteration so basically the statement from the continue to the end of the loop body are skipped okay now you might say why you might need such a statement so here is an example so we look at the same mark averaging problem but now we have an additional condition so what is this condition so suppose somebody types a number bigger than 100 then we are going to say that look that must have been a mistake so if it is a mistake what should we do we should just ignore it or in other words we should just not execute the statements that come after after this reading statement okay and therefore the continue the continuous statement will come in handy okay and as before we want to stop and print the average only when a negative number is read and so the other parts will remain the same so here is the new program with this new additional requirement so the main difference is this statement if next mark is bigger than 100 we continue which means we will skip this entire part and will start again okay so essentially this last mark that you read is going to be ignored otherwise if it is if it is less than 100 less than or equal to 100 then it is a valid mark and so we do everything that we were doing earlier now I should probably talk about one more statement the do while statement but I am not going to do so because it is not very common okay and it has been discussed in the book so I will leave it for you to read but I am not really going to I am not going to ask any problems regarding this statement and you do not really need to know it to solve any of the problems that we are going to discuss in this class in this course so you can use the break statement to advantage in writing that turtle controller program as well so instead of replicating you can use the break statement and so that is a good exercise just to check whether you have understood the break statement alright so what have we discussed so we have discussed the break statement which arrivals us to break or exit from a loop inside the body now a point to be noted is that if a break appears inside a vile statement which itself is nested inside another vile then the break only breaks out of the inner vile not out of the outer vile okay and then we also discussed the continuous statement which enables us to skip the rest of the iteration so we will take a break here and return later.