Doubt in IF ELSE BOX of pseudocode of PRIME NUMBER CHECKER EXAMPLE

In the previous video it said the format for the If Else statement is first write the IF and then 1st statement then write ELSE and then write the 2nd statement but in this QUESTION “ELSE IS NOT WRITTEN” why?

Yes in the video there’s no else block bhaiya has drawn, why so? It’s because we are only checking that if n is divisible by I or not. If we get that n is divisible by I it means that n has a factor I, so it can’t be prime number and if we didn’t get it there’s no divisor of n so it’s a prime number.
Ps : you can also add else statement, but bhaiya has avoided to reduce a single iteration for faster running of the program.

I just started this course 2 days ago so I did not understand the last 2 lines of your answer after the P.S. please explain that again
And even if we are checking whether the number is prime or not only ,there is an IF AND ELSE STATEMENT so why Is the ELSE BOX not present?

Okay i got it ,
Let me explain you it in detail. First tell me that you know the concept of prime numbers or not. So that i can frame a better explanation.

Yes I do . I’m just worried that my fundamentals should be strong

Okay so let me explain it to you in detail.
If else statements work on only 2 format, and they are

  1. If statement {
    // few statements or operations
    }
    Else {
    //few operations
    }
  2. If statement{
    //few operations
    }

Now you will notice in 2, we aren’t using any else statement. And it’s acceptable but if you use else and there’s no if statement above it. It will throw you an error. For eg

int n=5
Else{
//some conditions
}
In this syntax it will throw you an error because there’s no if statement to support else statements. So what do we learn is if statement can work without else statements, but else statements cannot work with if statements.

If you still have any doubt, feel free to ask. I would be happy to help :slight_smile:

In the answer you explained

In this you said that ELSE does not WORL

In this you said ELSE does not work when IF not present but in this Pseudocode IF is present so why will it shoe ERROR?

It won’t show error in the case where if is present and no else. It will throw error when there is no if but only has else.
In short , both if - else :heavy_check_mark:
Only If :heavy_check_mark:
Only Else :x:

Yeah in the above case IF is there so if I use else will it show error?Because in the video bhaiya has used IF and not ELSE so if I added ELSE BOX will it show error?

I mean bhaiya in the video used IF BOX and not ELSE BOX my question is if I added ELSE BOX will the Pseudocode be correct or show error?Im referring to the above question solved in the video

No brother, it won’t show any error if you will add any else box . As there’s already an if box which will support it.

Thanks a lot Bhaiya! Got it

It’s okay bro. Please don’t forget to mark your doubt resolved :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

I just had a friend run this code for both the cases once when we use else and the other when we dont use else and the CODE DOESNT WORK WHEN WE WRITE ELSE IT WORKS ONLY WHEN ELSE IS NOT WRITTEN BASED ON THE PSEUDOCODE PRATEEK SIR WROTE IN THE VIDEO. My doubt is here because you said even if I add ELSE BOX it will BOT SHOW ERROR.

NOT* INSTEAD OF BOT in the last line typing error

See you are using for loop in this problem so when your if condition fails, your for loop increase the value of I , and if you will use while loop instead of for loop then your else statement will come in action and your else statement will increase the value of I, so in for loop no else statement is required.