Monday, June 4, 2012

May someone explain this to me

So, I was working on my organ, so that it is easier to play, and I was working with if else statements. After a couple of if else statements, the code stopped working--I mean the program would not execute what was in the bottom if else statements. I then put an if on one of the statements where it was failing to execute, and maintained the other if else statements as if else statements, and band, the code worked. This is beyond my understanding really? Does anyone know why? Is it because ChucK can only accept a certain amount  of if-else statements? Is that even feasible? Is there a limit to cases you can have?

Confused

3 comments:

  1. I wonder if you have a line of code that keeps you from going to the last "if-else" statement. That may be why the "if" would work, because whatever test you are using for that final "if-else" (that works when you use an "if") is covered by the previous "if else". For example:


    int x = 0;

    while (true) {
    if (x > 0) {

    do something;

    } else if(x > 1) {

    do something else;

    }

    x++;
    }

    in the above case, "do something else" will never execute, because if x>1, it is always greater than 0, and the rest of the if-else block won't run because one of the tests has already passed. However, if you put it as an "if" inside of the "if (x > 0)" bracket, it will execute.

    That's really the only situation I could see causing the problem, otherwise it's an issue with ChucK.

    ReplyDelete
  2. My code did not have anything that would prevent me for going forward. I just did not understand the mystery. Everything was okay, but things never worked as expected. Thanks hey.

    ReplyDelete
  3. Lucy, is it the code you posted yesterday? Perhaps you could email the code to me?

    ReplyDelete