Talk:Control Structures: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
Created page with 'Using '''else''' we can have a code block which executes when the if statement evaluates to true, and another code block which executes when the if statement evaluates to false. …'
 
imported>StDoodle
No edit summary
Line 1: Line 1:
Using '''else''' we can have a code block which executes when the if statement evaluates to true, and another code block which executes when the if statement evaluates to false.
Ok, old version no longer needed. A couple cleanup requests:
<code>
* add return
    if(false)
* change looping to flow control OR add a separate section for continue, break & return
      {
* the above 3 should each have a lv3 heading
      print("this line never gets printed");
--[[User:StDoodle|StDoodle (#1059825)]] 18:57, 18 April 2010 (UTC)
      }
      else
      {
      print("this line gets printed");
      }
</code>
<Br/>
<Br/>
We also need to understand nesting if statements.
 
<code>
  if(true)
    {
    if(true)
      {
      print("this line gets printed");
      }
      else
      {
      print("this line never gets printed");
      }   
    print("this line gets printed also");
    }
  if(false)
    {
    if(true)
      {
      print("this line never gets printed");
      //though inside an if(true) statement,  
      //the outer if(false) stops the code from ever getting here.
      }
      else
      {
      print("this line never gets printed");
      }
    print("this line never gets printed");
    }
</code>
<Br/>
<Br/>
Now you only need to put it all together as needed for your situation.

Revision as of 18:57, 18 April 2010

Ok, old version no longer needed. A couple cleanup requests:

  • add return
  • change looping to flow control OR add a separate section for continue, break & return
  • the above 3 should each have a lv3 heading

--StDoodle (#1059825) 18:57, 18 April 2010 (UTC)