80.0k views
22 votes
You have been asked to write a loop that outputs values in a database column ranging between 10 and 100. Any number that is not divisible by 5, and any value that is not an integer, should be ignored. When the value in the loop hits 95, break the loop prematurely. One of your team members has advised the use of break, continue, and pass statements.

User Tymek
by
5.8k points

1 Answer

10 votes

Step-by-step explanation:

This is going to depend on the language you're working in heavily.

First you will want to verify your number is an integer rather than a floating point which will completely depend on the language and whether you care if the floating point is 1.0 for example, which could still be converted a valid integer value.

After you've determined if it is an integer you can use modulo to check if the integer is evenly divisible by 5. In C-like languages you would write this as `x % 5`. Any result other than zero would mean it is not evenly divisible.

You also need to check if the integer is >= 10 and <= 100.

Read up on for/while loops and break/continue in those loops to understand that concept, it is pretty universal to all languages.

Good luck!

User Bkach
by
5.5k points