0

It doesn't work if we use only if-condition. Why so?

2

Kareem has the right answer (as usual), per your example, if you did not use a forever loop, the cat would check if it was being petted once after you click the green flag, and see that you are not touching it that very moment, and stop checking. The forever loop makes it stay checking.

| improve this answer | |
  • To see this in action, put in a "say" statement in the forever loop to see it constantly checking the condition. Then implement it without the forever loop. It will check once, then be done with it. – KernelRutgers Mar 4 '15 at 21:18
0

An if block/condition is different from a forever block/loop in the sense that a loop, in general, keeps repeating while some condition is true. A forever loop, in particular, as its name suggests keeps repeating forever.

An if condition is only checked once and executed if it is true or not executed otherwise.

| improve this answer | |
  • i know for what it is used. I want to know why it is used in that particular case of pet-the-cat example in Scratch? The program can be implemented without using forever loop. Right? If not, then why? That's my question. – Palash Shendre Mar 4 '15 at 11:46
  • @PalashShendre let me ask you first, how do you think it could be implemented without a forever block? – Kareem Mar 4 '15 at 12:21

You must log in to answer this question.

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