Day 21

 Hello


Continuing what we studied yesterday.

There is a command called "continue" which is an alternative command to the "break" command. Instead of exiting the loop, it continues the loop ignoring the rejected command.

An example of the same as yesterday's example, but by changing break to continue. In yesterday's example, when adding a positive number, it adds it to the next positive number. For example, the program design takes 7 positive numbers and adds them, and each time it asks for the first and second numbers, and so on. When entering a negative number in yesterday's example, it exits the loop and adds the positive numbers that you entered previously.

But in today's example, when you enter a negative number, it prints an unacceptable value and continues in the loop again.

Example: The program asks to enter the first number. I entered 50, so it prints. I enter the second number and I enter -20. Then it prints an unacceptable value and prints. Enter the third number again because it did not take the second number beforehand.

Both commands have different uses. We determine which one to use according to what we want the program to do.

تعليقات

المشاركات الشائعة