Jump to content

Hello, I got a little problem with an if condition in Pascal. If you're wondering why in Pascal, it's because in my first year of college they teach us Pascal (idk why tho).

 

The program is something like this:

 

program activity1;

var
  	species: integer;
	zone: 1..50;
	locality: 1..25;

begin
    readln(species);
    readln(zone);
    readln(locality);

	(later in the program)
	if((zone >= 1) and (zone <= 10)) and ((locality = 3) or (locality = 8) or (locality = 9)) then
		writeln('Species code ', species, ' belongs to the South.'); 

and I get the following warning:

 

activity_1.pas(58,13) Warning: Comparison might be always true due to range of constant and expression

 

The activity asks us to read some stuff, which we can find these, expressed like this: "zone code(1..50), locality zone(1..25), species code, etc,". The thing is, we must send the program perfect with no warnings nor issues, and I'm getting this. I don't know if I explained well but I hope it was enough.

 

If you can help me, I'll be thankful. I can't find what's wrong, I hope you can.

 

Thanks for reading.

Link to comment
https://linustechtips.com/topic/914467-little-condition-problem-on-pascal/
Share on other sites

Link to post
Share on other sites

3 minutes ago, Unimportant said:

Since 'zone' can only ever be within the range 1..50 the expression:


zone >= 1

Will always be true and can be removed, that should clear the warning.

So, what should i replace it for? Because I'm asked to check if that condition is true in order to print something.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×