March 28, 2024, 12:28:06 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


IF Else Statement

Started by pistol350, July 22, 2007, 04:36:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pistol350

Hi all!
I often have problems with IF ELSE statements.
It is not that i can't fix them.I just want to understand once and for all why i often get synthax error (caused by the use of else ) for this kind of statements :

  if (m_baBoundsAction == BA_WRAP)
  {
    if ((ptNewPosition.x + ptSpriteSize.x) < m_rcBounds.left)
      ptNewPosition.x = m_rcBounds.right;
    else if (ptNewPosition.x > m_rcBounds.right)
      ptNewPosition.x = m_rcBounds.left - ptSpriteSize.x;
    if ((ptNewPosition.y + ptSpriteSize.y) < m_rcBounds.top)
      ptNewPosition.y = m_rcBounds.bottom;
    else if (ptNewPosition.y > m_rcBounds.bottom)
      ptNewPosition.y = m_rcBounds.top - ptSpriteSize.y;
  }

I don't think the best idea is to use the square brackets with each If condition. ???
Any suggestions please so that i no longer have to ask myself such ... questions  ;D
Thanks!

Regards!
Peter
Regards,

Peter B.

sapero

If you don't use brackets, remove the semicolon before 'else'
if (1 == 1) blah() else if (1 == 2) blah() else

pistol350

Yes!
I remember that i noticed something similar in the user guide.
Thank you Sap ! Your help is much appreciated!
Cheers!
Peter
Regards,

Peter B.