Difference between revisions of "Code Size/Cheat sheet"
RednaxelaBot (talk | contribs) m (Using <syntaxhighlight>.) |
(do while ....) |
||
| Line 109: | Line 109: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | |- | ||
| + | | style="margin:0; background:#e0efef; border:1px solid #a3bfb1; font-weight: bold; text-align:left; color:#000; padding:0.1em 0.4em;" | Loop with while | ||
| + | |- | ||
| + | |style="text-align:justify"| | ||
| + | You should always end up with less code size if you switch your for{each}( ...) loops to while loops. This applies to Lists as well to Arrays, just put an try..catch.. around the while to save the null, zero or "array out of bound" check. | ||
| + | |||
| + | Do this: | ||
| + | <syntaxhighlight> | ||
| + | public void onScannedRobot(ScannedRobotEvent e) { | ||
| + | try { | ||
| + | Iterator<your_class> iter = yourList.iterator(); | ||
| + | while(true) { | ||
| + | your_class obj = iter.next(); | ||
| + | ...... // your code | ||
| + | } | ||
| + | } catch (Exception e) {} | ||
| + | |||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | Don't do this: (8 byte more) | ||
| + | <syntaxhighlight> | ||
| + | public void onScannedRobot(ScannedRobotEvent e) { | ||
| + | foreach(your_class obj: yourList) { | ||
| + | ...... // your code | ||
| + | } | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
|} | |} | ||
| style="width: 40%; vertical-align:top;" | | | style="width: 40%; vertical-align:top;" | | ||
Revision as of 16:18, 23 May 2012
| This article is a stub. You can help RoboWiki by expanding it. |
Code Size Cheat sheet
|
|