Talk:Control Structures

From Kolmafia
Revision as of 19:18, 13 March 2010 by 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. …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

   if(false)
     {
     print("this line never gets printed");
     }
     else
     {
     print("this line gets printed"); 
     } 



We also need to understand nesting if statements.

 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");
   }



Now you only need to put it all together as needed for your situation.