Day 20
Hello, back to our course
Today we will talk about a feature in the loop, which is the break
For example, we made a program to take 7 positive numbers from the user and add them and print the result, but if the user adds a negative number, the program prints this value, which is not allowed, and prints the sum of the positive numbers that the user entered previously, and this is the function of the breakSo after writing the command, we add the conditional if and tell the computer if the entered number is less than 0 (negative)
We write the word "break" and its function is that it does not see the commands that follow it and it will exit the loop immediately and print the sum of the previous positive numbers
The importance of this command is that it helps speed up the program and reduces processing, and this increases the efficiency of the program and allows it to be run on many devices with weak capabilities


تعليقات
إرسال تعليق