<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic If...Else Statement not working properly in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/If-Else-Statement-not-working-properly/m-p/138385#M2159</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Krude here. I am experiencing problem with the If...Else statement. I know it's very simple but I not sure why that after the condition match, the program would not go into the code but jump out of the If....Else statement. Attached below is my code*no modification done*. The statement works on my main code body but not after I place it on another file, so I can use it as an object. Thanks for helping me out. Arigatou!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;---------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "derivative.h"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "M68DEMO908GB60" /*customized header file for GB60DEMO board*/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "timer.h" //customized header file for timer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "leds.h" //customized header file for LED&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "sine.h" //customized header file for sine wave&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "dac.h"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "swtiches.h"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int ichoice;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int iTimActPerioddef;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int swit::check (void){&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int iwaitmain=0, iSW2flag, iSW3flag,FFreqFlag=0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;timer2 Timer1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if(SW4 == DOWN){ //SW1 start the data transfer process&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if(ichoice=31){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;iTimActPerioddef = 96;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TPM1C0SC_CH0IE = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FFreqFlag = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}else if (ichoice&amp;gt;31){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FFreqFlag = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TPM1C0SC_CH0IE = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;} else if (SW2 == DOWN){ //SW2 increase the frequency&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;iSW2flag = 1;//the flag will be set when SW2 is pressed down. Flag is to prevent multi-increment of the ichoice&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;} else if(iSW2flag == 1 &amp;amp;&amp;amp; SW2 == UP){&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if(ichoice 36){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ichoice ++;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;iSW2flag = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Timer1.timdelay(1000);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;} else if(SW3 == DOWN){ //SW3 decrease the frequency&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;iSW3flag = 1;//the flag will be set when SW2 is pressed down. Flag is to prevent multi-decrement of the ichoice&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;} else if(iSW3flag == 1 &amp;amp;&amp;amp; SW3 == UP) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if(ichoice &amp;gt; 0){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ichoice --;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;iSW3flag = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Timer1.timdelay(1000);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;} else{&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;return FFreqFlag;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 Jun 2006 17:24:09 GMT</pubDate>
    <dc:creator>krude</dc:creator>
    <dc:date>2006-06-06T17:24:09Z</dc:date>
    <item>
      <title>If...Else Statement not working properly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/If-Else-Statement-not-working-properly/m-p/138385#M2159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Krude here. I am experiencing problem with the If...Else statement. I know it's very simple but I not sure why that after the condition match, the program would not go into the code but jump out of the If....Else statement. Attached below is my code*no modification done*. The statement works on my main code body but not after I place it on another file, so I can use it as an object. Thanks for helping me out. Arigatou!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;---------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "derivative.h"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "M68DEMO908GB60" /*customized header file for GB60DEMO board*/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "timer.h" //customized header file for timer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "leds.h" //customized header file for LED&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "sine.h" //customized header file for sine wave&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "dac.h"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "swtiches.h"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int ichoice;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int iTimActPerioddef;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int swit::check (void){&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int iwaitmain=0, iSW2flag, iSW3flag,FFreqFlag=0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;timer2 Timer1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if(SW4 == DOWN){ //SW1 start the data transfer process&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if(ichoice=31){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;iTimActPerioddef = 96;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TPM1C0SC_CH0IE = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FFreqFlag = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}else if (ichoice&amp;gt;31){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FFreqFlag = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TPM1C0SC_CH0IE = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;} else if (SW2 == DOWN){ //SW2 increase the frequency&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;iSW2flag = 1;//the flag will be set when SW2 is pressed down. Flag is to prevent multi-increment of the ichoice&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;} else if(iSW2flag == 1 &amp;amp;&amp;amp; SW2 == UP){&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if(ichoice 36){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ichoice ++;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;iSW2flag = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Timer1.timdelay(1000);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;} else if(SW3 == DOWN){ //SW3 decrease the frequency&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;iSW3flag = 1;//the flag will be set when SW2 is pressed down. Flag is to prevent multi-decrement of the ichoice&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;} else if(iSW3flag == 1 &amp;amp;&amp;amp; SW3 == UP) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if(ichoice &amp;gt; 0){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ichoice --;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;iSW3flag = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Timer1.timdelay(1000);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;} else{&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;return FFreqFlag;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jun 2006 17:24:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/If-Else-Statement-not-working-properly/m-p/138385#M2159</guid>
      <dc:creator>krude</dc:creator>
      <dc:date>2006-06-06T17:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: If...Else Statement not working properly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/If-Else-Statement-not-working-properly/m-p/138386#M2160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Hi Krude,&lt;/P&gt;&lt;P&gt;I don't know which &lt;FONT face="Courier New"&gt;If..Else&lt;/FONT&gt; statement you are referring to but some of the code will not be reached because of the single &lt;FONT face="Courier New"&gt;=&lt;/FONT&gt; in&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;if(ichoice=31)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;instead of&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;if(ichoice==31)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;However,&amp;nbsp;since you also have &lt;FONT face="Courier New"&gt;if(ichoice 36)&lt;/FONT&gt; maybe that is also&amp;nbsp;just a typo in creating your post and nothing to do with the problem?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Malcolm&lt;/P&gt;&lt;P&gt;Message Edited by MH on &lt;SPAN class="date_text"&gt;06-06-2006&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;07:32 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jun 2006 19:28:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/If-Else-Statement-not-working-properly/m-p/138386#M2160</guid>
      <dc:creator>MH</dc:creator>
      <dc:date>2006-06-06T19:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: If...Else Statement not working properly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/If-Else-Statement-not-working-properly/m-p/138387#M2161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, I don't know how to edit my text, so I double post. And apparently, I pasted my code but forget to do some checking. Hehe. The code was pasted incorrectly. And sorry again for not specifying which If...Else. I was refering to the If...Else statement which contains my SW4, SW2, SW3 as parameters. If you can see, my higher priority If...Else statement is the statement which contains my SW4 and etc...&lt;BR /&gt;P.S please ignore the If..Else which uses parameter, ichoice because that is not the problem If...Else. I am facing. Thanks. &amp;gt;.&lt;BR /&gt;---------------------------------------------------------------------&lt;BR /&gt;&lt;BR /&gt;#include "M68DEMO908GB60.h" /*customized header file for GB60DEMO board*/&lt;BR /&gt;#include "timer.h" //customized header file for timer&lt;BR /&gt;#include "leds.h" //customized header file for LED&lt;BR /&gt;#include "sine.h" //customized header file for sine wave&lt;BR /&gt;#include "dac.h"&lt;BR /&gt;#include "swtiches.h"&lt;BR /&gt;&lt;BR /&gt;int ichoice;&lt;BR /&gt;int iTimActPerioddef;&lt;BR /&gt;&lt;BR /&gt;int swit::check (void){&lt;BR /&gt;&lt;BR /&gt;int iwaitmain=0, iSW2flag, iSW3flag,FFreqFlag=0;&lt;BR /&gt;&lt;BR /&gt;timer2 Timer1;&lt;BR /&gt;&lt;BR /&gt;if(SW4 == DOWN){ //SW1 start the data transfer process&lt;BR /&gt;&lt;BR /&gt;if(ichoice==31){&lt;BR /&gt;iTimActPerioddef = 96;&lt;BR /&gt;TPM1C0SC_CH0IE = 1;&lt;BR /&gt;FFreqFlag = 0;&lt;BR /&gt;}else if (ichoice&amp;gt;31){&lt;BR /&gt;FFreqFlag = 1;&lt;BR /&gt;TPM1C0SC_CH0IE = 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;} else if (SW2 == DOWN){ //SW2 increase the frequency&lt;BR /&gt;&lt;BR /&gt;iSW2flag = 1;&lt;BR /&gt;&lt;BR /&gt;} else if(iSW2flag == 1 &amp;amp;&amp;amp; SW2 == UP){&lt;BR /&gt;&lt;BR /&gt;if(ichoice&amp;gt; 36){&lt;BR /&gt;ichoice ++;&lt;BR /&gt;}&lt;BR /&gt;iSW2flag = 0;&lt;BR /&gt;Timer1.timdelay(1000);&lt;BR /&gt;&lt;BR /&gt;} else if(SW3 == DOWN){ //SW3 decrease the frequency&lt;BR /&gt;&lt;BR /&gt;iSW3flag = 1;&lt;BR /&gt;&lt;BR /&gt;} else if(iSW3flag == 1 &amp;amp;&amp;amp; SW3 == UP) {&lt;BR /&gt;&lt;BR /&gt;if(ichoice &amp;gt; 0){&lt;BR /&gt;ichoice --;&lt;BR /&gt;}&lt;BR /&gt;iSW3flag = 0;&lt;BR /&gt;Timer1.timdelay(1000);&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;return FFreqFlag;&lt;BR /&gt;}&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jun 2006 08:57:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/If-Else-Statement-not-working-properly/m-p/138387#M2161</guid>
      <dc:creator>krude</dc:creator>
      <dc:date>2006-06-08T08:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: If...Else Statement not working properly</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/If-Else-Statement-not-working-properly/m-p/138388#M2162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;if(SW4 == DOWN){ //SW1 start the data transfer process&lt;BR /&gt;&lt;BR /&gt;if(ichoice==31){&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;Does it have anything to do with the fact that the if() tests SW4, but your comment references SW1?&lt;/P&gt;&lt;P&gt;Just a thought,&lt;/P&gt;&lt;P&gt;Tomahawk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Jun 2006 01:43:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/If-Else-Statement-not-working-properly/m-p/138388#M2162</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2006-06-09T01:43:29Z</dc:date>
    </item>
  </channel>
</rss>

