1

Hi I am having some issues with some simple conditions on an if statement when using 'or' to define the action, the below is an example that will have as a result a string with eleven characters, however for some reason the else if statement keep been excecute when that is not correct

Doesnt have apex the functionality of using this 'or' inside and if statement? however when using the code below on the developer console I dont get any error and it is been exccecuted. So I dont understand what is going on

string a = 'test string';
integer b;
b = a.length();
if(b <= 2){
    system.debug('b is less or equal to 2');
}else if(b > 2 || b<5){
    system.debug(b + ' is in between 2 and 5');
}else{
    system.debug('definetly longer than 5');
}

the result: Using or within if statement, APEX

Thanks

1
  • you're using an OR. 11>2. check. Commented Apr 4, 2014 at 23:49

1 Answer 1

5

(b > 2 || b < 5) is true for the number 11 (11 is greater than 2).

Perhaps you meant instead (b > 2 && b < 5), which will be true for numbers between 2 and 5 (exclusive)?

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .