User Tools

Site Tools


control-constructs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
control-constructs [2015/02/11 06:39]
barryfp created
control-constructs [2017/06/23 09:42]
barryfp
Line 3: Line 3:
 If statements work exactly as in C or Java and can use the && and || operators to indicate logical and/or. You can also use ''​else if''​ and ''​else''​ blocks as in these languages. If statements work exactly as in C or Java and can use the && and || operators to indicate logical and/or. You can also use ''​else if''​ and ''​else''​ blocks as in these languages.
  
-<​code ​dana>+<​code ​d>
 if (a) if (a)
    {    {
-   ​out.println("​a is true!"​);+   ​out.println("​a is true!"​)
    }    }
 </​code>​ </​code>​
Line 12: Line 12:
 While loops allow you to loop through a section of logic many times based on some boolean condition, specified at the top of the loop. While loops allow you to loop through a section of logic many times based on some boolean condition, specified at the top of the loop.
  
-<​code ​dana>+<​code ​d>
 while (a) while (a)
    {    {
-   ​out.println("​a is true!"​);+   ​out.println("​a is true!"​)
    }    }
 </​code>​ </​code>​
Line 23: Line 23:
 For loops allow you to specify an initial variable status, a condition, and a modification to that variable each time around the loop: For loops allow you to specify an initial variable status, a condition, and a modification to that variable each time around the loop:
  
-<​code ​dana>+<​code ​d>
 for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
    {    {
-   ​out.println("​i is $(iu.intToString(i))"​);+   ​out.println("​i is $(iu.intToString(i))"​)
    }    }
 </​code>​ </​code>​
Line 34: Line 34:
 Finally, the special ''​break''​ statement can be used inside any kind of loop construct to break out of the loop when some other condition is encountered,​ for example: Finally, the special ''​break''​ statement can be used inside any kind of loop construct to break out of the loop when some other condition is encountered,​ for example:
  
-<​code ​dana>+<​code ​d>
 for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
    {    {
-   ​out.println("​i is $(iu.intToString(i))"​);+   ​out.println("​i is $(iu.intToString(i))"​)
        
    if (programExiting)    if (programExiting)
-      break;+      break
    }    }
 </​code>​ </​code>​
control-constructs.txt ยท Last modified: 2017/06/23 09:42 by barryfp